Skip to content

Commit 124a491

Browse files
committed
Infer implicit Reflection argument to Matcher.unapply
1 parent 7bae575 commit 124a491

File tree

3 files changed

+5
-4
lines changed

3 files changed

+5
-4
lines changed

compiler/src/dotty/tools/dotc/typer/Typer.scala

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1948,7 +1948,7 @@ class Typer extends Namer
19481948
fun = ref(defn.QuotedMatcher_unapplyR).appliedToType(patType),
19491949
implicits =
19501950
ref(defn.InternalQuoted_exprQuoteR).appliedToType(shape.tpe).appliedTo(shape) ::
1951-
givenReflection :: Nil,
1951+
givenReflection(tree.span) :: Nil,
19521952
patterns = splicePat :: Nil,
19531953
proto = pt)
19541954
}
@@ -1979,7 +1979,8 @@ class Typer extends Namer
19791979
def patternHole(splice: Tree)(implicit ctx: Context): Tree =
19801980
ref(defn.InternalQuoted_patternHoleR).appliedToType(splice.tpe).withSpan(splice.span)
19811981

1982-
def givenReflection(implicit ctx: Context): Tree = Literal(Constant(null)) // FIXME: fill in
1982+
def givenReflection(span: Span)(implicit ctx: Context): Tree =
1983+
implicitArgTree(defn.TastyReflectionType, span)
19831984

19841985
/** Translate `${ t: Expr[T] }` into expression `t.splice` while tracking the quotation level in the context */
19851986
def typedSplice(tree: untpd.Splice, pt: Type)(implicit ctx: Context): Tree = track("typedSplice") {

tests/neg/quotedPatterns.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ object Test {
55
def f(x: Int) = x
66
def g(x: Int, y: Int) = x * y
77

8-
x match {
8+
def test given tasty.Reflection = x match {
99
case '{ val a = '{ println($y) }; 0 } => ??? // error: Not found: y
1010
case _ =>
1111
}

tests/pos/quotedPatterns.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ object Test {
55
def f(x: Int) = x
66
def g(x: Int, y: Int) = x * y
77

8-
val res: quoted.Expr[Int] = x match {
8+
def res given tasty.Reflection: quoted.Expr[Int] = x match {
99
case '{1 + 2} => '{0}
1010
case '{f($y)} => y
1111
case '{g($y, $z)} => '{$y * $z}

0 commit comments

Comments
 (0)