Skip to content

Commit

Permalink
Add special modifier testing to FIR (#2192)
Browse files Browse the repository at this point in the history
  • Loading branch information
JakeWharton authored Jul 22, 2024
1 parent d4c59d3 commit ec14aaf
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ private fun parseModifier(
): ParsedProtocolModifier {
val memberFqType = memberType.toFqType()
val tag = annotation.tag
require(tag in 1 until MAX_MEMBER_TAG || isReservedModifier(tag, memberType)) {
require(tag in 1 until MAX_MEMBER_TAG || isSpecialModifier(tag, memberType.toFqType())) {
"@Modifier $memberFqType tag must be in range [1, $MAX_MEMBER_TAG): $tag"
}

Expand Down Expand Up @@ -482,9 +482,9 @@ private fun parseModifier(
)
}

/** Returns true if [memberType] is a known reserved tag name. */
private fun isReservedModifier(tag: Int, memberType: KClass<*>): Boolean {
return tag == -4_543_827 && memberType.simpleName == "Reuse"
/** Returns true if [memberType] is a known special modifier tag and name. */
internal fun isSpecialModifier(tag: Int, memberType: FqType): Boolean {
return tag == -4_543_827 && memberType.names.last() == "Reuse"
}

private fun KAnnotatedElement.parseDeprecation(source: () -> String): ParsedDeprecation? {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,7 @@ private fun FirContext.parseModifier(
annotation: ModifierAnnotation,
): ParsedProtocolModifier {
val tag = annotation.tag
require(tag in 1 until MAX_MEMBER_TAG) {
require(tag in 1 until MAX_MEMBER_TAG || isSpecialModifier(tag, memberType)) {
"@Modifier $memberType tag must be in range [1, $MAX_MEMBER_TAG): $tag"
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -642,6 +642,23 @@ class SchemaParserTest(
)
}

@Schema(
[
Reuse::class,
],
)
interface SpecialModifierSchema

@Modifier(-4_543_827)
data object Reuse

@Test fun specialModifiersAllowed() {
val schema = parser.parse(SpecialModifierSchema::class).schema

val modifier = schema.modifiers.single()
assertThat(modifier.tag).isEqualTo(-4_543_827)
}

@Schema([SomeWidget::class, SomeModifier::class])
interface SchemaTag

Expand Down

0 comments on commit ec14aaf

Please sign in to comment.