Skip to content

Commit a68048d

Browse files
committed
SI-6891 Fix value class + tailrec crasher.
rhs.substituteSymbols(old, new) leaves us with: def loop#12225(x#12226: A#15491): scala#21.this.Unit#1615 = loop#12225(x#12226) In which the TermSymbol x#12226 has a stale info, pointing at the A#7274, the class type parameter, rather than A#15491, the corresponding type parameter of the synthetic backing method. I've improved `TreeSymSubstituter` to substitute not only `Tree#{tpe, symbol}`, but also `DefTree#sym.info`. The `pos` test that triggered the new code path are listed here: https://gist.github.com/4575687
1 parent 6f72ed8 commit a68048d

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

src/reflect/scala/reflect/internal/Trees.scala

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1439,6 +1439,18 @@ trait Trees extends api.Trees { self: SymbolTable =>
14391439
if (tree.tpe ne null) tree.tpe = symSubst(tree.tpe)
14401440
if (tree.hasSymbol) {
14411441
subst(from, to)
1442+
tree match {
1443+
case _: DefTree =>
1444+
val newInfo = symSubst(tree.symbol.info)
1445+
if (!(newInfo =:= tree.symbol.info)) {
1446+
debuglog(sm"""
1447+
|TreeSymSubstituter: updated info of symbol ${tree.symbol}
1448+
| Old: ${showRaw(tree.symbol.info, printTypes = true, printIds = true)}
1449+
| New: ${showRaw(newInfo, printTypes = true, printIds = true)}""")
1450+
tree.symbol updateInfo newInfo
1451+
}
1452+
case _ =>
1453+
}
14421454
tree match {
14431455
case Ident(name0) if tree.symbol != NoSymbol =>
14441456
treeCopy.Ident(tree, tree.symbol.name)

test/files/pos/t6891.scala

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
object O {
2+
implicit class Foo[A](val value: String) extends AnyVal {
3+
def bippy() = {
4+
@annotation.tailrec def loop(x: A): Unit = loop(x)
5+
()
6+
}
7+
8+
def boppy() = {
9+
@annotation.tailrec def loop(x: value.type): Unit = loop(x)
10+
()
11+
}
12+
}
13+
// uncaught exception during compilation: Types$TypeError("type mismatch;
14+
// found : A(in method bippy$extension)
15+
// required: A(in class Foo)") @ scala.tools.nsc.typechecker.Contexts$Context.issueCommon(Contexts.scala:396)
16+
// error: scala.reflect.internal.Types$TypeError: type mismatch;
17+
// found : A(in method bippy$extension)
18+
// required: A(in class Foo)
19+
}

0 commit comments

Comments
 (0)