File tree 12 files changed +149
-1
lines changed
compiler/src/dotty/tools/dotc/transform
12 files changed +149
-1
lines changed Original file line number Diff line number Diff line change @@ -119,7 +119,8 @@ class PCPCheckAndHeal(@constructorOnly ictx: Context) extends TreeMapWithStages(
119
119
// Replace it with a properly encoded type splice. This is the normal for expected for type splices.
120
120
tp.prefix.select(tpnme.splice)
121
121
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 {
123
124
case Some (tpRef) => tpRef.tpe
124
125
case _ =>
125
126
if (tp.symbol.is(Param )) tp
Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change
1
+ object Test {
2
+ def main (args : Array [String ]): Unit = {
3
+ mcr()
4
+ }
5
+ }
You can’t perform that action at this time.
0 commit comments