Skip to content

Commit a06d31f

Browse files
committed
Keep annotations when computing lubs
Integrates annotationsLub into lub. Also fixes SubstSymMap when mapping over annotaion trees. I don't understand what the previous code was supposed to achieve, but it crashed in some of my examples.
1 parent 6697c28 commit a06d31f

File tree

2 files changed

+12
-17
lines changed

2 files changed

+12
-17
lines changed

src/reflect/scala/reflect/internal/Types.scala

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4706,23 +4706,13 @@ trait Types extends api.Types { self: SymbolTable =>
47064706
case idx => Some(to(idx))
47074707
}
47084708

4709-
override def transform(tree: Tree) =
4710-
tree match {
4711-
case tree@Ident(_) =>
4712-
termMapsTo(tree.symbol) match {
4713-
case Some(tosym) =>
4714-
if (tosym.info.bounds.hi.typeSymbol isSubClass SingletonClass) {
4715-
Ident(tosym.existentialToString)
4716-
.setSymbol(tosym)
4717-
.setPos(tosym.pos)
4718-
.setType(dropSingletonType(tosym.info.bounds.hi))
4719-
} else {
4720-
giveup()
4721-
}
4722-
case none => super.transform(tree)
4723-
}
4724-
case tree => super.transform(tree)
4709+
override def transform(tree: Tree) = {
4710+
termMapsTo(tree.symbol) match {
4711+
case Some(tosym) => tree.symbol = tosym
4712+
case None => ()
47254713
}
4714+
super.transform(tree)
4715+
}
47264716
}
47274717
trans.transform(tree)
47284718
}
@@ -6618,7 +6608,7 @@ trait Types extends api.Types { self: SymbolTable =>
66186608
val ts0 = elimSub0(ts)
66196609
if (ts0.isEmpty || ts0.tail.isEmpty) ts0
66206610
else {
6621-
val ts1 = ts0 mapConserve (t => elimAnonymousClass(t.underlying))
6611+
val ts1 = ts0 mapConserve (t => elimAnonymousClass(t.dealiasWiden))
66226612
if (ts1 eq ts0) ts0
66236613
else elimSub(ts1, depth)
66246614
}
@@ -6735,6 +6725,8 @@ trait Types extends api.Types { self: SymbolTable =>
67356725
NullaryMethodType(lub0(matchingRestypes(ts, Nil)))
67366726
case ts @ TypeBounds(_, _) :: rest =>
67376727
TypeBounds(glb(ts map (_.bounds.lo), depth), lub(ts map (_.bounds.hi), depth))
6728+
case ts @ AnnotatedType(annots, tpe, _) :: rest =>
6729+
annotationsLub(lub0(ts map (_.withoutAnnotations)), ts)
67386730
case ts =>
67396731
lubResults get (depth, ts) match {
67406732
case Some(lubType) =>

test/files/pos/lubs.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
object Test {
2+
List(new { def f = 1; def g = 1}, new { def f = 2}).map(_.f)
3+
}

0 commit comments

Comments
 (0)