Skip to content

Commit 1f2ca04

Browse files
committed
Drop incorrect optimization in substituters
The optimization was to disregard a prefix of a named type if its symbol is static and none of the mapped symbols in `from` is static. This is incorrect, since the prefix might be a non-static reference to a static object. In that case the prefix still has to be considered. i2895a.scala contains code that failed when running with the cbn implementation of `assert` in the next commit.
1 parent b2cc163 commit 1f2ca04

File tree

2 files changed

+9
-14
lines changed

2 files changed

+9
-14
lines changed

compiler/src/dotty/tools/dotc/core/Substituters.scala

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ trait Substituters { this: Context =>
1212
case tp: BoundType =>
1313
if (tp.binder eq from) tp.copyBoundType(to.asInstanceOf[tp.BT]) else tp
1414
case tp: NamedType =>
15-
if (tp.currentSymbol.isStatic || (tp.prefix `eq` NoPrefix)) tp
15+
if (tp.prefix `eq` NoPrefix) tp
1616
else tp.derivedSelect(subst(tp.prefix, from, to, theMap))
1717
case _: ThisType =>
1818
tp
@@ -26,7 +26,7 @@ trait Substituters { this: Context =>
2626
case tp: NamedType =>
2727
val sym = tp.symbol
2828
if (sym eq from) return to
29-
if (sym.isStatic && !from.isStatic || (tp.prefix `eq` NoPrefix)) tp
29+
if (tp.prefix `eq` NoPrefix) tp
3030
else tp.derivedSelect(subst1(tp.prefix, from, to, theMap))
3131
case _: ThisType | _: BoundType =>
3232
tp
@@ -42,7 +42,7 @@ trait Substituters { this: Context =>
4242
val sym = tp.symbol
4343
if (sym eq from1) return to1
4444
if (sym eq from2) return to2
45-
if (sym.isStatic && !from1.isStatic && !from2.isStatic || (tp.prefix `eq` NoPrefix)) tp
45+
if (tp.prefix `eq` NoPrefix) tp
4646
else tp.derivedSelect(subst2(tp.prefix, from1, to1, from2, to2, theMap))
4747
case _: ThisType | _: BoundType =>
4848
tp
@@ -63,7 +63,7 @@ trait Substituters { this: Context =>
6363
fs = fs.tail
6464
ts = ts.tail
6565
}
66-
if (sym.isStatic && !existsStatic(from) || (tp.prefix `eq` NoPrefix)) tp
66+
if (tp.prefix `eq` NoPrefix) tp
6767
else tp.derivedSelect(subst(tp.prefix, from, to, theMap))
6868
case _: ThisType | _: BoundType =>
6969
tp
@@ -85,7 +85,7 @@ trait Substituters { this: Context =>
8585
fs = fs.tail
8686
ts = ts.tail
8787
}
88-
if (sym.isStatic && !existsStatic(from) || (tp.prefix `eq` NoPrefix)) tp
88+
if (tp.prefix `eq` NoPrefix) tp
8989
else tp.derivedSelect(substSym(tp.prefix, from, to, theMap))
9090
case tp: ThisType =>
9191
val sym = tp.cls
@@ -123,7 +123,7 @@ trait Substituters { this: Context =>
123123
case tp @ RecThis(binder) =>
124124
if (binder eq from) to else tp
125125
case tp: NamedType =>
126-
if (tp.currentSymbol.isStatic || (tp.prefix `eq` NoPrefix)) tp
126+
if (tp.prefix `eq` NoPrefix) tp
127127
else tp.derivedSelect(substRecThis(tp.prefix, from, to, theMap))
128128
case _: ThisType | _: BoundType =>
129129
tp
@@ -137,7 +137,7 @@ trait Substituters { this: Context =>
137137
case tp: BoundType =>
138138
if (tp == from) to else tp
139139
case tp: NamedType =>
140-
if (tp.currentSymbol.isStatic || (tp.prefix `eq` NoPrefix)) tp
140+
if (tp.prefix `eq` NoPrefix) tp
141141
else tp.derivedSelect(substParam(tp.prefix, from, to, theMap))
142142
case _: ThisType =>
143143
tp
@@ -151,7 +151,7 @@ trait Substituters { this: Context =>
151151
case tp: ParamRef =>
152152
if (tp.binder == from) to(tp.paramNum) else tp
153153
case tp: NamedType =>
154-
if (tp.currentSymbol.isStatic || (tp.prefix `eq` NoPrefix)) tp
154+
if (tp.prefix `eq` NoPrefix) tp
155155
else tp.derivedSelect(substParams(tp.prefix, from, to, theMap))
156156
case _: ThisType =>
157157
tp
@@ -160,11 +160,6 @@ trait Substituters { this: Context =>
160160
.mapOver(tp)
161161
}
162162

163-
private def existsStatic(syms: List[Symbol]): Boolean = syms match {
164-
case sym :: syms1 => sym.isStatic || existsStatic(syms1)
165-
case nil => false
166-
}
167-
168163
final class SubstBindingMap(from: BindingType, to: BindingType) extends DeepTypeMap {
169164
def apply(tp: Type) = subst(tp, from, to, this)
170165
}

compiler/src/dotty/tools/dotc/core/Symbols.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -643,7 +643,7 @@ object Symbols {
643643
* the implicit conversion `sourcePos` will return the wrong result, careful!
644644
* TODO: Consider changing this method return type to `SourcePosition`.
645645
*/
646-
def pos: Position = if (coord.isPosition) coord.toPosition else NoPosition
646+
final def pos: Position = if (coord.isPosition) coord.toPosition else NoPosition
647647

648648
// ParamInfo types and methods
649649
def isTypeParam(implicit ctx: Context) = denot.is(TypeParam)

0 commit comments

Comments
 (0)