Skip to content

Commit d92bf6e

Browse files
committed
Improve type inference of quote pattern splices
Infer higher bound for type splices. This means that when type information is not given the pattern should match all term that could fit in this hole.
1 parent 9535ea6 commit d92bf6e

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ trait QuotesAndSplices {
7373
case _ =>
7474
}
7575
if (ctx.mode.is(Mode.QuotedPattern))
76-
if (isFullyDefined(pt, ForceDegree.all)) {
76+
if (isFullyDefined(pt, ForceDegree.flipBottom)) {
7777
def spliceOwner(ctx: Context): Symbol =
7878
if (ctx.mode.is(Mode.QuotedPattern)) spliceOwner(ctx.outer) else ctx.owner
7979
val pat = typedPattern(tree.expr, defn.QuotedExprClass.typeRef.appliedTo(pt))(
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import scala.quoted._
2+
3+
4+
object Macros {
5+
6+
inline def g(inline x: Unit): Unit = ${impl('x)}
7+
8+
private def impl(x: Expr[Any])(using QuoteContext): Expr[Any] = {
9+
x match
10+
case '{ println(f($y)) } => y
11+
}
12+
13+
}
14+
15+
def f[T](x: T): T = x
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import Macros._
2+
3+
4+
object Test {
5+
6+
def main(args: Array[String]): Unit = {
7+
g(println(f((5))))
8+
}
9+
10+
}

0 commit comments

Comments
 (0)