Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix TreeTypeMap to correctly substitute type parameters #14537

Merged
merged 5 commits into from
Feb 23, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 13 additions & 1 deletion compiler/src/dotty/tools/dotc/ast/TreeTypeMap.scala
Original file line number Diff line number Diff line change
Expand Up @@ -204,11 +204,23 @@ class TreeTypeMap(
lazy val origCls = mapped.zip(syms).filter(_._1.isClass).toMap
mapped.filter(_.isClass).foldLeft(substMap) { (tmap, cls) =>
val origDcls = cls.info.decls.toList.filterNot(_.is(TypeParam))
val mappedDcls = mapSymbols(origDcls, tmap, mapAlways = true)
val tmap0 = tmap.withSubstitution(origCls(cls).typeParams, cls.typeParams)
val mappedDcls = mapSymbols(origDcls, tmap0, mapAlways = true)
val tmap1 = tmap.withMappedSyms(
origCls(cls).typeParams ::: origDcls,
cls.typeParams ::: mappedDcls)
origDcls.lazyZip(mappedDcls).foreach(cls.asClass.replace)
tmap1
}

override def toString =
def showSyms(syms: List[Symbol]) =
syms.map(sym => s"$sym#${sym.id}").mkString(", ")
s"""TreeTypeMap(
|typeMap = $typeMap
|treeMap = $treeMap
|oldOwners = ${showSyms(oldOwners)}
|newOwners = ${showSyms(newOwners)}
|substFrom = ${showSyms(substFrom)}
|substTo = ${showSyms(substTo)}""".stripMargin
}
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/reporting/trace.scala
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ trait TraceSyntax:
else
// Avoid evaluating question multiple time, since each evaluation
// may cause some extra logging output.
val q = question.replace('\n', ' ')
val q = question
dwijnand marked this conversation as resolved.
Show resolved Hide resolved
val leading = s"==> $q?"
val trailing = (res: T) => s"<== $q = ${showOp(res)}"
var finalized = false
Expand Down
8 changes: 8 additions & 0 deletions tests/pos/i12508.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class Test {
inline def test(fun: Any): Any = ???
test {
class Foo[X]:
def x: X = ???
def foo: Unit = this.x.toString
}
}
14 changes: 14 additions & 0 deletions tests/pos/i12508a.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
def fun(a: Any, b: Any = 2): Any = ???
def test =
fun(
b = println(1),
a = {
class Foo[X]:
def x: X = ???
def foo: Unit = this.x.toString
locally {
def x: X = ???
println(x.toString)
}
}
)