Skip to content

Commit 098c50a

Browse files
authored
Merge pull request #1832 from dotty-staging/fix-1810
Fix #1812, Symbols.mapSymbols shouldn't replace denotations
2 parents afa8309 + a7d17e2 commit 098c50a

File tree

3 files changed

+40
-7
lines changed

3 files changed

+40
-7
lines changed

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

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -316,25 +316,35 @@ trait Symbols { this: Context =>
316316
newNakedSymbol[original.ThisName](original.coord)
317317
}
318318
val ttmap1 = ttmap.withSubstitution(originals, copies)
319-
(originals, copies).zipped foreach {(original, copy) =>
320-
copy.denot = original.denot // preliminary denotation, so that we can access symbols in subsequent transform
321-
}
322-
(originals, copies).zipped foreach {(original, copy) =>
319+
(originals, copies).zipped foreach { (original, copy) =>
323320
val odenot = original.denot
324321
val oinfo = original.info match {
325322
case ClassInfo(pre, _, parents, decls, selfInfo) =>
326323
assert(original.isClass)
327324
ClassInfo(pre, copy.asClass, parents, decls.cloneScope, selfInfo)
328325
case oinfo => oinfo
329326
}
327+
328+
val completer = new LazyType {
329+
def complete(denot: SymDenotation)(implicit ctx: Context): Unit = {
330+
denot.info = oinfo // needed as otherwise we won't be able to go from Sym -> parents & etc
331+
// Note that this is a hack, but hack commonly used in Dotty
332+
// The same thing is done by other completers all the time
333+
denot.info = ttmap1.mapType(oinfo)
334+
denot.annotations = odenot.annotations.mapConserve(ttmap1.apply)
335+
}
336+
}
337+
330338
copy.denot = odenot.copySymDenotation(
331339
symbol = copy,
332340
owner = ttmap1.mapOwner(odenot.owner),
333-
initFlags = odenot.flags &~ Frozen | Fresh,
334-
info = ttmap1.mapType(oinfo),
341+
initFlags = odenot.flags &~ (Frozen | Touched) | Fresh,
342+
info = completer,
335343
privateWithin = ttmap1.mapOwner(odenot.privateWithin), // since this refers to outer symbols, need not include copies (from->to) in ownermap here.
336-
annotations = odenot.annotations.mapConserve(ttmap1.apply))
344+
annotations = odenot.annotations)
345+
337346
}
347+
338348
copies
339349
}
340350

tests/pos/i1812.scala

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
class FF[R] {
2+
def compose(): R = ???
3+
}
4+
5+
class Test(x: Int) extends AnyVal {
6+
def method: Unit = {
7+
class Bla
8+
class Foo extends FF[Bla] {
9+
override def compose() = super[FF].compose()
10+
}
11+
}
12+
}

tests/pos/i1812b.scala

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
class FF[R] {
2+
def compose(): R = ???
3+
}
4+
5+
class Test(x: Int) extends AnyVal {
6+
def method: Unit = {
7+
class Bla{ def bar:a.S = ???}
8+
trait TRT{ type S}
9+
val a: TRT = ???
10+
}
11+
}

0 commit comments

Comments
 (0)