Skip to content

Commit 1e328b0

Browse files
2 parents a39960a + e22016f commit 1e328b0

File tree

12 files changed

+149
-1
lines changed

12 files changed

+149
-1
lines changed

compiler/src/dotty/tools/dotc/transform/PCPCheckAndHeal.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,8 @@ class PCPCheckAndHeal(@constructorOnly ictx: Context) extends TreeMapWithStages(
119119
// Replace it with a properly encoded type splice. This is the normal for expected for type splices.
120120
tp.prefix.select(tpnme.splice)
121121
case tp: NamedType =>
122-
checkSymLevel(tp.symbol, tp, pos) match {
122+
if (tp.prefix.isInstanceOf[TermRef] && tp.prefix.isStable) tp
123+
else checkSymLevel(tp.symbol, tp, pos) match {
123124
case Some(tpRef) => tpRef.tpe
124125
case _ =>
125126
if (tp.symbol.is(Param)) tp

tests/neg/i5954b.scala

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
abstract class MatcherFactory1[A] {
2+
class AndNotWord
3+
}
4+
5+
object MatcherFactory1 {
6+
import scala.quoted._
7+
8+
def impl[T](self: Expr[MatcherFactory1[T]#AndNotWord]) given QuoteContext =
9+
'{ val a: Any = $self } // error: access to type T from wrong staging level
10+
11+
}

tests/neg/i5954c.scala

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
abstract class MatcherFactory1 {
2+
class AndNotWord[A]
3+
}
4+
5+
object MatcherFactory1 {
6+
import scala.quoted._
7+
8+
def impl[T](self: Expr[MatcherFactory1#AndNotWord[T]]) given QuoteContext =
9+
'{ val a: Any = $self } // error: access to type T from wrong staging level
10+
11+
}

tests/pos/i5954b.scala

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
abstract class MatcherFactory1 {
2+
class AndNotWord[A]
3+
}
4+
5+
object MatcherFactory1 {
6+
import scala.quoted._
7+
8+
def impl(self: Expr[MatcherFactory1#AndNotWord[Int]]) given QuoteContext =
9+
'{ val a: Any = $self }
10+
11+
12+
def impl[T: Type](self: Expr[MatcherFactory1#AndNotWord[T]]) given QuoteContext =
13+
'{ val a: Any = $self }
14+
15+
}

tests/pos/i5954c.scala

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
abstract class MatcherFactory1[A] {
2+
class AndNotWord
3+
}
4+
5+
object MatcherFactory1 {
6+
import scala.quoted._
7+
8+
def impl(self: Expr[MatcherFactory1[Int]#AndNotWord]) given QuoteContext =
9+
'{ val a: Any = $self }
10+
11+
12+
def impl[T: Type](self: Expr[MatcherFactory1[T]#AndNotWord]) given QuoteContext =
13+
'{ val a: Any = $self }
14+
15+
}

tests/pos/i5954d.scala

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
abstract class MatcherFactory1 {
2+
type AndNotWord
3+
}
4+
5+
object MatcherFactory1 {
6+
import scala.quoted._
7+
8+
def impl(self: Expr[MatcherFactory1#AndNotWord]) given QuoteContext =
9+
'{ val a: Any = $self }
10+
11+
12+
def impl2[T: Type](a: MatcherFactory1)(self: Expr[T])(implicit ev: T =:= a.AndNotWord, qctx: QuoteContext) =
13+
'{ val a: Any = $self }
14+
15+
}

tests/pos/i7048.scala

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import scala.quoted._
2+
3+
trait IsExpr[T] {
4+
type Underlying
5+
def expr: Expr[Underlying]
6+
}
7+
8+
def f(x: Any): String = x.toString
9+
10+
def g[T] given (e: IsExpr[T], tu: Type[e.Underlying]): given QuoteContext => Expr[String] = {
11+
val underlying: Expr[e.Underlying] = e.expr
12+
'{f($underlying)}
13+
}

tests/pos/i7048b.scala

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import scala.quoted._
2+
3+
trait IsExpr {
4+
type Underlying
5+
}
6+
7+
val foo: IsExpr = ???
8+
9+
def g() given QuoteContext: Unit = {
10+
val a = '[foo.Underlying]
11+
()
12+
}

tests/pos/i7048c.scala

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import scala.quoted._
2+
3+
trait IsExpr {
4+
type Underlying
5+
}
6+
7+
val foo: IsExpr = ???
8+
9+
def g(e: IsExpr) given (tu: Type[e.Underlying]): Unit = ???
10+
11+
def mcrImpl given QuoteContext: Unit = {
12+
g(foo)
13+
}

tests/pos/i7048d.scala

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import scala.quoted._
2+
3+
trait IsExpr {
4+
class Underlying
5+
}
6+
7+
val foo: IsExpr = ???
8+
9+
def g(e: IsExpr) given (tu: Type[e.Underlying]): Unit = ???
10+
11+
def mcrImpl given QuoteContext: Unit = {
12+
g(foo)
13+
}

tests/run-macros/i7048/Lib_1.scala

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import scala.quoted._
2+
3+
trait IsExpr[T] {
4+
type Underlying
5+
def toExpr(x: T): Expr[Underlying]
6+
}
7+
8+
given [U] as IsExpr[Expr[U]] = new IsExpr[Expr[U]] {
9+
type Underlying = U
10+
def toExpr(x: Expr[U]): Expr[U] = x
11+
}
12+
13+
def f(x: Any): String = x.toString
14+
15+
def g[T](x: T) given (e: IsExpr[T], tu: Type[e.Underlying]): given QuoteContext => Expr[String] = {
16+
val underlying: Expr[e.Underlying] = e.toExpr(x)
17+
'{f($underlying)}
18+
}
19+
20+
inline def mcr(): Any = ${mcrImpl}
21+
def mcrImpl given QuoteContext: Expr[Any] = {
22+
val x = '{1}
23+
g(x)
24+
}

tests/run-macros/i7048/Test_2.scala

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
object Test {
2+
def main(args: Array[String]): Unit = {
3+
mcr()
4+
}
5+
}

0 commit comments

Comments
 (0)