Skip to content

Kotlin 2.1+ consumers cannot compile generated metamodels against the null-marked API #458

Description

@zantvoort

Since the JSpecify adoption (#456), the three Kotlin SmokeCompileTest cases in storm-gradle-plugin fail, and with them the CI build on main. The smoke projects compile a real consumer against the installed artifacts, and the KSP-generated sources no longer compile there:

CityNullableMetamodel.kt: Type argument is not within its bounds: type parameter 'V' (of class AbstractMetamodel)
CityNullableMetamodel.kt: Type argument is not within its bounds: type parameter 'V' (of class AbstractKeyMetamodel)
CityInstantiator.kt: Class 'CityInstantiator' is not abstract and does not implement abstract member
CityInstantiator.kt: 'instantiate' overrides nothing

@NullMarked on the st.orm packages gives every unbounded type parameter an implicit non-null bound, and Kotlin 2.1+ enforces JSpecify strictly. That contradicts what the API means in three places:

  • V in TypedMetamodel/AbstractMetamodel/AbstractKeyMetamodel is the declared component type, and the generated <Type>NullableMetamodel chain deliberately binds it to a nullable type (City?, Ref<City>?). The parameter must declare V extends @Nullable Object.
  • Metamodel.getValue documents "or null if the value cannot be resolved" but now reads as returning non-null Object, so a generated nullable getValue override cannot narrow it. The return must be @Nullable Object (and KeyDelegate's delegating override with it).
  • Instantiator.instantiate(Object[] args) now reads as an array of non-null elements, while the arguments are canonical constructor values that include nullable components; the generated Kotlin instantiate(args: Array<Any?>) therefore overrides nothing. The parameter must be @Nullable Object[]. deconstruct has the reverse defect: @Nullable Object[] annotates the elements only, so the array reads non-null although the default returns null; it must be @Nullable Object @Nullable [].

The reactor build cannot catch this class of error: storm-kotlin builds with Kotlin 2.0 and strict JSpecify enforcement starts at 2.1; the smoke projects build with Kotlin 2.4. The smoke suite is the acceptance test.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingcorestorm-core and foundation work

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions