Skip to content

Commit

Permalink
Check level consistency of SingletonTypeTree as a type (#17209)
Browse files Browse the repository at this point in the history
Fixes #8887
  • Loading branch information
nicolasstucki authored Apr 13, 2023
2 parents e940957 + b08729b commit 73af81e
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class CrossStageSafety extends TreeMapWithStages {
val healedType = healType(tree.srcPos)(tp1)
if healedType == tree.tpe then tree
else TypeTree(healedType).withSpan(tree.span)
case _: RefTree if tree.isType =>
case _: RefTree | _: SingletonTypeTree if tree.isType =>
val healedType = healType(tree.srcPos)(tree.tpe)
if healedType == tree.tpe then tree
else TypeTree(healedType).withSpan(tree.span)
Expand Down
5 changes: 5 additions & 0 deletions tests/neg-macros/i8887.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import scala.quoted._

def expr[X](x: Any)(using Quotes): Expr[Any] =
'{ foo[x.type] } // error
def foo[X]: Any = ???
4 changes: 1 addition & 3 deletions tests/neg-macros/quote-this-a.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ class Foo {

def f(using Quotes): Unit = '{
def bar[T](x: T): T = x
bar[
this.type // error
] {
bar[this.type] {
this // error
}
}
Expand Down
3 changes: 3 additions & 0 deletions tests/pos-macros/i8887.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import scala.quoted._
inline def foo(x: Any): Any = ${ expr[x.type] }
def expr[X](using Quotes): Expr[Any] = ???

0 comments on commit 73af81e

Please sign in to comment.