File tree Expand file tree Collapse file tree 7 files changed +63
-30
lines changed
compiler/src/dotty/tools/dotc Expand file tree Collapse file tree 7 files changed +63
-30
lines changed Original file line number Diff line number Diff line change @@ -202,13 +202,17 @@ class PCPCheckAndHeal(@constructorOnly ictx: Context) extends TreeMapWithStages(
202
202
val reqType = defn.QuotedTypeType .appliedTo(tp)
203
203
val tag = ctx.typer.inferImplicitArg(reqType, pos.span)
204
204
tag.tpe match {
205
- case fail : SearchFailureType =>
205
+ case _ : TermRef =>
206
+ Some (tag.select(tpnme.splice))
207
+ case _ : SearchFailureType =>
206
208
levelError(i """
207
209
|
208
210
| The access would be accepted with the right type tag, but
209
211
| ${ctx.typer.missingArgMsg(tag, reqType, " " )}""" )
210
212
case _ =>
211
- Some (tag.select(tpnme.splice))
213
+ levelError(i """
214
+ |
215
+ | The access would be accepted with an implict $reqType""" )
212
216
}
213
217
}
214
218
case _ =>
Original file line number Diff line number Diff line change @@ -61,6 +61,15 @@ class Staging extends MacroTransform {
61
61
checker.transform(tree)
62
62
case _ =>
63
63
}
64
+
65
+ tree.tpe match {
66
+ case tpe @ TypeRef (prefix, _) if tpe.typeSymbol eq defn.QuotedType_splice =>
67
+ // Type splices must have a know term ref, usually to an implicit argument
68
+ // This is mostly intended to catch `quoted.Type[T]#splice` types which should just be `T`
69
+ assert(prefix.isInstanceOf [TermRef ], prefix)
70
+ case _ =>
71
+ // OK
72
+ }
64
73
}
65
74
}
66
75
Original file line number Diff line number Diff line change @@ -673,33 +673,21 @@ trait Implicits { self: Typer =>
673
673
EmptyTree
674
674
}
675
675
676
+ /** Synthesize the tree for `'[T]` for an implicit `scala.quoted.Type[T]`.
677
+ * `T` is deeply dealiassed to avoid references to local type aliases.
678
+ */
676
679
def synthesizedTypeTag (formal : Type ): Tree = {
677
680
def quotedType (t : Type ) = {
678
681
if (StagingContext .level == 0 )
679
682
ctx.compilationUnit.needsStaging = true // We will need to run ReifyQuotes
680
683
ref(defn.InternalQuoted_typeQuote ).appliedToType(t)
681
684
}
682
685
formal.argInfos match {
683
- case arg :: Nil if ! arg.typeSymbol.is(Param ) =>
684
- object bindFreeVars extends TypeMap {
685
- var ok = true
686
- def apply (t : Type ) = t match {
687
- case t @ TypeRef (NoPrefix , _) =>
688
- inferImplicit(defn.QuotedTypeType .appliedTo(t), EmptyTree , span) match {
689
- case SearchSuccess (tag, _, _) if tag.tpe.isStable =>
690
- tag.tpe.select(defn.QuotedType_splice )
691
- case _ =>
692
- ok = false
693
- t
694
- }
695
- case _ => t
696
- }
686
+ case arg :: Nil =>
687
+ val deepDealias = new TypeMap {
688
+ def apply (tp : Type ): Type = mapOver(tp.dealias)
697
689
}
698
- val tag = bindFreeVars(arg)
699
- if (bindFreeVars.ok) quotedType(tag)
700
- else EmptyTree
701
- case arg :: Nil if ctx.inInlineMethod =>
702
- quotedType(arg)
690
+ quotedType(deepDealias(arg))
703
691
case _ =>
704
692
EmptyTree
705
693
}
Original file line number Diff line number Diff line change @@ -14,12 +14,4 @@ class Test {
14
14
15
15
' {(y : Expr [Int ]) => $y } // error: wrong staging level
16
16
17
- def f [T ](t : Type [T ], x : Expr [T ]) = ' {
18
- val z2 = $x // error // error: wrong staging level
19
- }
20
-
21
- def g [T ](implicit t : Type [T ], x : Expr [T ]) = ' {
22
- val z2 = $x // ok
23
- }
24
-
25
17
}
Original file line number Diff line number Diff line change
1
+ import scala .quoted ._
2
+
3
+ class Test {
4
+
5
+ def f [T ](t : Type [T ], x : Expr [T ]) = ' {
6
+ val z2 = $x // error // error: wrong staging level
7
+ }
8
+
9
+ def g [T ](implicit t : Type [T ], x : Expr [T ]) = ' {
10
+ val z2 = $x // ok
11
+ }
12
+
13
+ }
Original file line number Diff line number Diff line change
1
+ import scala .quoted ._
2
+
3
+ inline def foo [T : Type ]: Int = 10
4
+
5
+ def main = {
6
+ type S = Int
7
+ foo[S ]
8
+ foo[Int ]
9
+
10
+ type T = Int => Int
11
+ foo[T ]
12
+ foo[Int => Int ]
13
+
14
+ type U = List [Int ]
15
+ foo[U ]
16
+ foo[List [Int ]]
17
+
18
+ type N = List
19
+ foo[N ]
20
+ foo[List ]
21
+
22
+ type V = List [S ]
23
+ foo[V ]
24
+
25
+ type B = V => T
26
+ foo[B ]
27
+ }
Original file line number Diff line number Diff line change 1
1
(null: scala.Any).asInstanceOf[java.lang.Object]
2
- (null: scala.Any).asInstanceOf[scala.Predef .String]
2
+ (null: scala.Any).asInstanceOf[java.lang .String]
You can’t perform that action at this time.
0 commit comments