Skip to content

Compilation fails with Kotlin 2.3.20 due to stricter generic bounds enforcement #4583

@hugoncosta

Description

@hugoncosta

smithy-rs fails to compile with Kotlin 2.3.20 (released 2026-03-16). Two files are affected:

1. codegen-serverServerProtocolBasedTransformationFactory.kt

The removeTraitIfPresent extension function has a phantom type parameter B that is only used in a where clause and an unchecked cast. Kotlin 2.3.20's stricter type inference rejects the call sites because it cannot verify B is within its bounds.

e: ServerProtocolBasedTransformationFactory.kt:50:44 Type argument is not within its bounds: must be subtype of 'AbstractShapeBuilder<SmithyBuilder<OperationShape!>, OperationShape!>'

2. codegen-aws-sdkMakeS3BoolsAndNumbersOptional.kt

AbstractShapeBuilder<*, *> is used as an explicit type annotation, but AbstractShapeBuilder has a recursive self-referential bound (<B extends AbstractShapeBuilder<B, S>, S extends Shape>). Kotlin 2.3.20 now enforces that * satisfies this bound.

e: MakeS3BoolsAndNumbersOptional.kt:31:69 Type argument is not within its bounds:
  must be subtype of 'AbstractShapeBuilder<AbstractShapeBuilder<...>!, SimpleShape!>!'

Both issues compile fine on Kotlin 2.1.0 (the current version)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions