Skip to content

Commit 0de9768

Browse files
committed
Drop parameter accessor flag in traits
Parameter accessors in traits have the ParamAccessor flag removed in the Mixin transformSym method.
1 parent ece6ed4 commit 0de9768

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

src/dotty/tools/dotc/transform/Mixin.scala

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import collection.mutable
2020

2121
/** This phase performs the following transformations:
2222
*
23-
* 1. (done in `traitDefs` and `transformSym`) Map every concrete trait getter
23+
* 1. (done in `traitDefs` and `transformSym`) Map every concrete trait getter
2424
*
2525
* <mods> def x(): T = expr
2626
*
@@ -83,6 +83,8 @@ import collection.mutable
8383
* 4. (done in `transformTemplate` and `transformSym`) Drop all parameters from trait
8484
* constructors.
8585
*
86+
* 5. (done in `transformSym`) Drop ParamAccessor flag from all parameter accessors in traits.
87+
*
8688
* Conceptually, this is the second half of the previous mixin phase. It needs to run
8789
* after erasure because it copies references to possibly private inner classes and objects
8890
* into enclosing classes where they are not visible. This can only be done if all references
@@ -97,7 +99,7 @@ class Mixin extends MiniPhaseTransform with SymTransformer { thisTransform =>
9799

98100
override def transformSym(sym: SymDenotation)(implicit ctx: Context): SymDenotation =
99101
if (sym.is(Accessor, butNot = Deferred) && sym.owner.is(Trait))
100-
sym.copySymDenotation(initFlags = sym.flags | Deferred).ensureNotPrivate
102+
sym.copySymDenotation(initFlags = sym.flags &~ ParamAccessor | Deferred).ensureNotPrivate
101103
else if (sym.isConstructor && sym.owner.is(Trait) && sym.info.firstParamTypes.nonEmpty)
102104
sym.copySymDenotation(info = MethodType(Nil, sym.info.resultType))
103105
else
@@ -124,7 +126,7 @@ class Mixin extends MiniPhaseTransform with SymTransformer { thisTransform =>
124126
def traitDefs(stats: List[Tree]): List[Tree] = {
125127
val initBuf = new mutable.ListBuffer[Tree]
126128
stats.flatMap({
127-
case stat: DefDef if stat.symbol.isGetter && !stat.rhs.isEmpty && !stat.symbol.is(Flags.Lazy) =>
129+
case stat: DefDef if stat.symbol.isGetter && !stat.rhs.isEmpty && !stat.symbol.is(Flags.Lazy) =>
128130
// make initializer that has all effects of previous getter,
129131
// replace getter rhs with empty tree.
130132
val vsym = stat.symbol
@@ -197,7 +199,7 @@ class Mixin extends MiniPhaseTransform with SymTransformer { thisTransform =>
197199
def initial = transformFollowing(superRef(initializer(getter)).appliedToNone)
198200
if (isCurrent(getter) || getter.is(ExpandedName)) {
199201
val rhs =
200-
if (getter.is(ParamAccessor)) nextArgument()
202+
if (ctx.atPhase(thisTransform)(implicit ctx => getter.is(ParamAccessor))) nextArgument()
201203
else if (isScala2x) Underscore(getter.info.resultType)
202204
else transformFollowing(superRef(initializer(getter)).appliedToNone)
203205
// transformFollowing call is needed to make memoize & lazy vals run

tests/run/traitParams.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@ trait U extends T {
1010
State.s += 1
1111
override def f = super.f + y
1212
}
13+
trait U2(a: Any) extends T {
14+
def d = a // okay
15+
val v = a // okay
16+
a // used to crash
17+
}
18+
1319
import State._
1420
class C(x: Int) extends U with T(x, x * x + s)
1521
class C2(x: Int) extends T(x, x * x + s) with U

0 commit comments

Comments
 (0)