Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid erasure/preErasure issues around Any in transformIsInstanceOf #21647

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

dwijnand
Copy link
Member

The testType Any is erased to Object, but the expr type Int isn't erased
to Integer, so then it fails as Int !<: Object. We avoid the problem by
feeding in AnyVal, leading to a (possibly elided) non-null test only.

Fixes #21544

The testType Any is erased to Object, but the expr type Int isn't erased
to Integer, so then it fails as Int !<: Object.  We avoid the problem by
feeding in AnyVal, leading to a (possibly elided) non-null test only.
@dwijnand dwijnand marked this pull request as ready for review September 25, 2024 22:27
@dwijnand dwijnand requested a review from sjrd September 25, 2024 22:27
Comment on lines +362 to +363
if testType.isAny && expr.tpe.isPrimitiveValueType then
defn.AnyValType
Copy link
Member

Choose a reason for hiding this comment

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

Isn't that going to trigger with the same issue with any other type that erases to Object? Like ... AnyVal itself?

There's supposed to already be logic in transformIsInstanceOf to avoid a type test when expr.tpe <:< testType:

if (expr.tpe <:< testType) && inMatch then
if expr.tpe.isNotNull then constant(expr, Literal(Constant(true)))
else expr.testNotNull

The problem is that it tests on erased types, instead of the original types. Addressing that at the root should be more robust, shouldn't it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

For comprehension bug when using type casting
2 participants