-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Fix checking ctx to carry correct modes #15350
Conversation
test performance please |
performance test scheduled: 1 job(s) in queue, 0 running. |
Performance test finished successfully: Visit https://dotty-bench.epfl.ch/15350/ to see the changes. Benchmarks is based on merging with main (42b5941) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's better to drop imports in Erasure during the regular tree pass. E.g. add:
override def typedImport(imp: untpd.Import, sym: Symbol)(using Context) = EmptyTree
4833ebc
to
0cd0778
Compare
test performance please |
performance test scheduled: 3 job(s) in queue, 1 running. |
Hi @odersky , I removed the This PR is ready for another review now. Thanks |
Performance test finished successfully: Visit https://dotty-bench.epfl.ch/15350/ to see the changes. Benchmarks is based on merging with main (140693d) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Otherwise LGTM
val expr1 = typedExpr(tree.expr, pt.dropIfProto)(using exprCtx) | ||
var expr1 = typedExpr(tree.expr, pt.dropIfProto)(using exprCtx) | ||
|
||
// If unsafe nulls is enabled inside a block but not enabled outside |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment does not correspond to the code. exprCtx
is the context inside the block valid for the final expression. ctx
is the context outside the block. The cast is performed if unsafeNulls is disabled inside the block but enabled around it. Is this what's intended? Either the comment or the code has to be fixed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the comment is correct: !exprCtx.mode.is(Mode.SafeNulls)
indicates SafeNulls
is disabled inside the block, which means unsafeNulls is enabled here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The confusion is that the mode is SafeNulls
which is a negation of unsafeNulls
. I think the comment correctly corresponds to the code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, my bad. I misread the code.
In
TreeChecker
, the context for checking is not initialized properly.val checkingCtx
usessetMode(Mode.ImplicitsEnabled)
, which removes other modes in the ctx.This causes
Mode.SafeNulls
removed from the context. So the checking for explicit nulls tests is always running with unsafe nulls enabled!!This PR fixs the checking ctx and some other bugs exposed by the correct checking:
if unsafe nulls is enabled inside but not enabled outside
and the type does not conform the expected type without unsafe nulls.
See:
tests/explicit-nulls/pos/unsafe-block.scala
null
toAnyRef
when generatingtestNotNull
nameRef
inSyntheticMembers.scala
, cast the result ofname
toString
ifisJavaEnumValue
#15096 is blocked by this PR, #14946 will also wait for this