Handle symbol.defTree properly for nested definitions in bindings #11550
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Handle symbol.defTree properly for nested definitions in bindings
Nested definitions in inlining bindings will get new symbols in
changeOwner
. TheSymbol.defTree
is never set for those symbols.The problem is exhibited in the following test
The fix in 0f034aa works by accident:
The reason is the following:
If we enable
-Ycheck:all
, it will sync the tree definition forall symbols during TreeChecker, thus no crash in initialization
checker.
if we disable
-Ycheck:all
, thedefTree
for<init>
is not set,initialization checker ignore the method, thus no crash.
However, if we change
InlineTyper
instead ofRetyper
:There will be some mysterious behavior in compiling
tests/pos/i10542.scala
:-Ycheck:all
, it succeeds-Ycheck:all
, the initialization check crashes due to missingdefTree
for the class$anon
.The reason for the mysterious behavior is the following:
Without
-Ycheck:all
, there is no defTree for<init>
,initialization check is skipped, thus no crash.
With
-Ycheck:all
, the methodTyper.typedDefDef
will setSymbol.defTree
for<init>
, called from the TreeChecker, whichextends
Typer
indirectly viaReTyper
. However, inTyper.typedClassDef
, we never setdefTree
for class symbols,thus the
defTree
for the class symbol$anon
is empty, causing anexception in initialization check.
Co-authored-by: Nicolas Stucki [email protected]