Skip to content

Kotlin: Fix findTopLevelPropertyOrWarn for K2 compiler - #21915

Open
david-allison wants to merge 1 commit into
github:mainfrom
david-allison:kotlin-dropped-class
Open

Kotlin: Fix findTopLevelPropertyOrWarn for K2 compiler#21915
david-allison wants to merge 1 commit into
github:mainfrom
david-allison:kotlin-dropped-class

Conversation

@david-allison

@david-allison david-allison commented May 30, 2026

Copy link
Copy Markdown

Note

Assisted-by: Claude Opus 4.8 - diagnostics & initial fix


Receiver::class.java resolves differently from K1:

  • K1: getJavaClass(KClass) - value argument
  • K2: KClass.<get-java>() - property receiver

This caused the lookup to fail, so Intent(context, Receiver::class.java) dropped the second argument.

"Couldn't find JVM intrinsic property kotlin.jvm java in kotlin.jvm.JvmClassMappingKt"

This caused false positives in java/android/implicit-pendingintents

@andersfugmann andersfugmann left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for submitting
The approach and solution is sound and looks good. Also thanks for adding tests.

I added one comment on making the filter slightly more readable.

If you could address that comment and rebase on latest main, this will be good to merge.

@david-allison

Copy link
Copy Markdown
Author

I added one comment on making the filter slightly more readable.

Hi @andersfugmann, thanks for the review. I don't see your comment in the GitHub UI, could you send a link? (Presumably for KotlinFileExtractor.kt‎, but I'd want to be certain).

I'll try and get to this before the weekend. Thanks again

Comment on lines +3906 to +3911
.firstOrNull {
val owner = it.owner
owner.parentClassOrNull?.fqNameWhenAvailable?.asString() == type ||
(owner.parent is IrExternalPackageFragment &&
getFileClassFqName(owner)?.asString() == type)
}

@andersfugmann andersfugmann Sep 9, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I understand correctly, the problem is that K2 in some cases the parent is not an IrClass but an IrExternalPackageFragment, in which case we need to access the name through call to getFileClassFqName. If so, I think it will be more readable by using a pattern match on the type if parent node, e.g:

    .firstOrNull {
        val owner = it.owner
        when (val parent = owner.parent) {
            is IrClass -> parent.fqNameWhenAvailable?.asString()
            is IrExternalPackageFragment -> getFileClassFqName(owner)?.asString()
            else -> null
        } == type
    }

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, cheers!

@andersfugmann

Copy link
Copy Markdown
Contributor

My bad. Forgot to submit the comment :-)

`Receiver::class.java` resolves differently from K1:

K1: getJavaClass(KClass) - value argument
K2: KClass.<get-java>() - property receiver

This caused the lookup to fail, so
`Intent(context, Receiver::class.java)` dropped the second argument.

log:
"Couldn't find JVM intrinsic property kotlin.jvm java in kotlin.jvm.JvmClassMappingKt"

This caused false positives in `java/android/implicit-pendingintents`

The fix mirrors 5c36e63

Fixes github#20153
Assisted-by: Claude Opus 4.8 - diagnostics & initial fix
Assisted-by: Claude Fable 5.1 - convert to 'when'; re-review
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

False positive "use of implicit PendingIntents" alert

2 participants