openrewrite / rewrite-kotlin

Work-in-progress implementation of Kotlin language support for OpenRewrite.
Apache License 2.0
38 stars 11 forks source link

Added type validation to Assertions. #543

Closed traceyyoshima closed 6 months ago

traceyyoshima commented 6 months ago

Changes:

fixes https://github.com/openrewrite/rewrite-kotlin/issues/482 fixes https://github.com/openrewrite/rewrite-kotlin/issues/474

traceyyoshima commented 6 months ago

Resolved: Blocked by https://github.com/openrewrite/rewrite-kotlin/issues/480. In J, switch expressions add the default keyword as an expression too. The else keyword in a Kotlin when expression is functionally the same. The FindMissingTypes recipe used for TypeValidation has a condition that accepts default and other case statements with null types. So, a similar condition has been added to validate Kotlin types in the LST.

traceyyoshima commented 6 months ago

@knutwannheden type validation is essentially ready for review. The failing tests are identifiers with aliases, and I'm looking into how to detect aliases.

import java.util.regex.Pattern.CASE_INSENSITIVE as i

class A {
    val f = arrayOf(i)
}
traceyyoshima commented 6 months ago

As we can disable validations on a test case basis, we can fix any remaining issues in follow up PRs.

Disabled the alias tests and opened: https://github.com/openrewrite/rewrite-kotlin/issues/545 to track a fix for aliases. Tracking the declarations of a name will allow us to apply the appropriate field type comparison.