Skip to content

Fix #4678: Create single Typed tree with multiple type annotations #5714

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

Merged
merged 2 commits into from
Jan 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion compiler/src/dotty/tools/dotc/typer/Typer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1767,8 +1767,19 @@ class Typer extends Namer
if (ctx.mode is Mode.Type)
assignType(cpy.Annotated(tree)(arg1, annot1), arg1, annot1)
else {
val arg2 = arg1 match {
case Typed(arg2, tpt: TypeTree) =>
tpt.tpe match {
case _: AnnotatedType =>
// Avoid creating a Typed tree for each type annotation that is added.
// Drop the outer Typed tree and use its type with the addition all annotation.
arg2
case _ => arg1
}
case _ => arg1
}
val tpt = TypeTree(AnnotatedType(arg1.tpe.widenIfUnstable, Annotation(annot1)))
assignType(cpy.Typed(tree)(arg1, tpt), tpt)
assignType(cpy.Typed(tree)(arg2, tpt), tpt)
}
}

Expand Down
1 change: 1 addition & 0 deletions compiler/test/dotc/pos-recompilation.whitelist
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ i4526a
i4526b
i4586
i4623
i4678
i4720
i4773
i4774a
Expand Down
14 changes: 14 additions & 0 deletions language-server/test/dotty/tools/languageserver/HoverTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -174,4 +174,18 @@ class HoverTest {
|}""".withSource
.hover(m1 to m2, hoverContent("Int", "hello"))
}

@Test def i4678: Unit = {
code"""class Foo {
| val x: Int = (${m1}1:${m2} ${m3}@annot1 @annot2 @annot3 @annot4 @annot5${m4})
|}
|class annot1 extends scala.annotation.Annotation
|class annot2 extends scala.annotation.Annotation
|class annot3 extends scala.annotation.Annotation
|class annot4 extends scala.annotation.Annotation
|class annot5 extends scala.annotation.Annotation
|""".withSource
.hover(m1 to m2, hoverContent("Int(1)"))
.hover(m3 to m4, hoverContent("Int(1) @annot1 @annot2 @annot3 @annot4 @annot5"))
}
}
14 changes: 14 additions & 0 deletions tests/pos/i4678.decompiled
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/** Decompiled from out/posTestFromTasty/pos/i4678/Foo.tasty */
class Foo() {
val x: scala.Int = (1: @annot1() @annot2() @annot3() @annot4() @annot5())
}
/** Decompiled from out/posTestFromTasty/pos/i4678/annot1.tasty */
class annot1() extends scala.annotation.Annotation()
/** Decompiled from out/posTestFromTasty/pos/i4678/annot2.tasty */
class annot2() extends scala.annotation.Annotation()
/** Decompiled from out/posTestFromTasty/pos/i4678/annot3.tasty */
class annot3() extends scala.annotation.Annotation()
/** Decompiled from out/posTestFromTasty/pos/i4678/annot4.tasty */
class annot4() extends scala.annotation.Annotation()
/** Decompiled from out/posTestFromTasty/pos/i4678/annot5.tasty */
class annot5() extends scala.annotation.Annotation()
9 changes: 9 additions & 0 deletions tests/pos/i4678.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class Foo {
val x: Int = (1: @annot1 @annot2 @annot3 @annot4 @annot5)
}

class annot1 extends scala.annotation.Annotation
class annot2 extends scala.annotation.Annotation
class annot3 extends scala.annotation.Annotation
class annot4 extends scala.annotation.Annotation
class annot5 extends scala.annotation.Annotation