Skip to content

Commit 772be76

Browse files
authored
Fix condition in prefixIsElidable to prevent compiler crash (#18924)
Fix #18901 The check in `prefixIsElidable` was defined as follows: ```scala tp.symbol.isParamOrAccessor && !pre.cls.is(Trait) && ctx.owner.enclosingClass == pre.cls ``` I assume that `!pre.cls.is(Trait)` condition was introduced to accommodate for `Mixin` phase getting rid of `ParamAccessor` defined in traits. However, the prefix does not indicate where the symbol is really defined - it only represents the prefix from the perspective of the current template, so it could be inherited. When it's inherited from a trait, the prefix would be the current class, but the member still is defined in the trait, and `Mixin` would get rid of the `ParamAccessor` flag. Therefore, I changed this condition to the following: ```scala tp.symbol.isParamOrAccesso && !pre.cls.is(Trait) && !tp.symbol.owner.is(Trait) && ctx.owner.enclosingClass == pre.cls ```
2 parents 50498d8 + 01a37ec commit 772be76

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

Diff for: compiler/src/dotty/tools/dotc/ast/tpd.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
414414
case pre: ThisType =>
415415
tp.isType ||
416416
pre.cls.isStaticOwner ||
417-
tp.symbol.isParamOrAccessor && !pre.cls.is(Trait) && ctx.owner.enclosingClass == pre.cls
417+
tp.symbol.isParamOrAccessor && !pre.cls.is(Trait) && !tp.symbol.owner.is(Trait) && ctx.owner.enclosingClass == pre.cls
418418
// was ctx.owner.enclosingClass.derivesFrom(pre.cls) which was not tight enough
419419
// and was spuriously triggered in case inner class would inherit from outer one
420420
// eg anonymous TypeMap inside TypeMap.andThen

Diff for: tests/pos/i18091.scala

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
trait B(val y: Int)
2+
3+
class C extends B(20) {
4+
def foo(): Unit = println(y)
5+
}

0 commit comments

Comments
 (0)