diff --git a/redwood-tooling-schema/src/main/kotlin/app/cash/redwood/tooling/schema/schemaParser.kt b/redwood-tooling-schema/src/main/kotlin/app/cash/redwood/tooling/schema/schemaParser.kt index 039ede5b20..e80a4f8807 100644 --- a/redwood-tooling-schema/src/main/kotlin/app/cash/redwood/tooling/schema/schemaParser.kt +++ b/redwood-tooling-schema/src/main/kotlin/app/cash/redwood/tooling/schema/schemaParser.kt @@ -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" } @@ -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? { diff --git a/redwood-tooling-schema/src/main/kotlin/app/cash/redwood/tooling/schema/schemaParserFir.kt b/redwood-tooling-schema/src/main/kotlin/app/cash/redwood/tooling/schema/schemaParserFir.kt index 6d253120bd..45c4007272 100644 --- a/redwood-tooling-schema/src/main/kotlin/app/cash/redwood/tooling/schema/schemaParserFir.kt +++ b/redwood-tooling-schema/src/main/kotlin/app/cash/redwood/tooling/schema/schemaParserFir.kt @@ -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" } diff --git a/redwood-tooling-schema/src/test/kotlin/app/cash/redwood/tooling/schema/SchemaParserTest.kt b/redwood-tooling-schema/src/test/kotlin/app/cash/redwood/tooling/schema/SchemaParserTest.kt index ad6185c329..5cb41dd6c2 100644 --- a/redwood-tooling-schema/src/test/kotlin/app/cash/redwood/tooling/schema/SchemaParserTest.kt +++ b/redwood-tooling-schema/src/test/kotlin/app/cash/redwood/tooling/schema/SchemaParserTest.kt @@ -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