Skip to content

Commit

Permalink
Merge pull request #9426 from tanishiking/singleton-type-tree-12296
Browse files Browse the repository at this point in the history
  • Loading branch information
SethTisue committed Jan 13, 2021
2 parents 8850b1f + 8a46016 commit f2d2e6e
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 3 deletions.
3 changes: 1 addition & 2 deletions src/compiler/scala/tools/nsc/typechecker/Typers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5627,9 +5627,8 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper

if (refTyped.isErrorTyped) setError(tree)
else {
tree setType refTyped.tpe.resultType.deconst
if (!treeInfo.admitsTypeSelection(refTyped)) UnstableTreeError(tree)
else tree
else SingletonTypeTree(refTyped).setType(refTyped.tpe.resultType.deconst)
}
}

Expand Down
2 changes: 1 addition & 1 deletion test/files/run/reify-each-node-type.check
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
23 new r.List[Int]() New
24 0: @unchecked Annotated
25 (null: r.Outer#Inner) SelectFromTypeTree
26 (null: Nil.type) SingletonTypeTree
26 (null: r.Nil.type) SingletonTypeTree
27 (null: T forSome { type T }) ExistentialTypeTree
28 { import r.{A, B=>C}; () } Import
29 { def f: Int = return 0; () } Return
Expand Down
37 changes: 37 additions & 0 deletions test/junit/scala/tools/nsc/typechecker/TypedTreeTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,41 @@ class TypedTreeTest extends BytecodeTesting {
val List(t) = tree.filter(_.attachments.all.nonEmpty).toList
assertEquals(s"$t:${t.attachments.all}", "42:Set(OriginalTreeAttachment(O.x))")
}


// Ensure SingletonTypeTree#ref is typed and it has symbol after typing.
// see: https://github.com/scala/bug/issues/12296
@Test
def singletonTypeTreeRefTyped(): Unit = {
val code =
"""|object root {
| object impl
| val f: impl.type => Unit = {
| case _: impl.type => ()
| }
|}
""".stripMargin
val run = compiler.newRun
run.compileSources(List(BytecodeTesting.makeSourceFile(code, "UnitTestSingletonTypeTreeSource.scala")))
val tree = run.units.next().body

import compiler.global._

val singletonTypeTrees = new collection.mutable.MutableList[SingletonTypeTree]
object traverser extends Traverser {
override def traverse(t: Tree): Unit = {
t match {
case tt: TypeTree if tt.original != null => traverse(tt.original)
case st: SingletonTypeTree =>
singletonTypeTrees += st
case _ => super.traverse(t)
}
}
}
traverser.traverse(tree)

singletonTypeTrees.foreach { t =>
assertEquals(t.ref.symbol.fullName, "root.impl")
}
}
}

0 comments on commit f2d2e6e

Please sign in to comment.