Skip to content

Commit 7169347

Browse files
authored
Backport "Do not beta-reduce/eta-expand pattern splices with contextual function types" to LTS (#19127)
Backports #18198 to the LTS branch. PR submitted by the release tooling. [skip ci]
2 parents 8eedd71 + 79cec4b commit 7169347

File tree

4 files changed

+46
-0
lines changed

4 files changed

+46
-0
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3103,6 +3103,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
31033103
&& xtree.isTerm
31043104
&& !untpd.isContextualClosure(xtree)
31053105
&& !ctx.mode.is(Mode.Pattern)
3106+
&& !xtree.isInstanceOf[SplicePattern]
31063107
&& !ctx.isAfterTyper
31073108
&& !ctx.isInlineContext
31083109
then
@@ -3945,6 +3946,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
39453946
&& pt != SingletonTypeProto
39463947
&& pt != AssignProto
39473948
&& !ctx.mode.is(Mode.Pattern)
3949+
&& !tree.isInstanceOf[SplicePattern]
39483950
&& !ctx.isAfterTyper
39493951
&& !ctx.isInlineContext
39503952
then

tests/pos-macros/i18197a.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import scala.quoted.*
2+
3+
def readPathMacro[A: Type, B: Type](expr: Expr[Any])(using Quotes) =
4+
expr match
5+
case '{ foo($y) } => y: Expr[Int ?=> Int]
6+
7+
def foo(x: Int ?=> Int): Any = ???

tests/pos-macros/i18197b/Macro.scala

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import scala.quoted.*
2+
3+
object ReproMacro {
4+
inline def readPath[A, B](inline config: Config[A, B]) = ${ readPathMacro[A, B]('config) }
5+
6+
def readPathMacro[A: Type, B: Type](expr: Expr[Config[A, B]])(using Quotes) = {
7+
import quotes.reflect.report
8+
9+
expr match {
10+
case '{ Field.const[a, b, tpe]($selector) } =>
11+
val selector2: Expr[Selector ?=> a => tpe] = selector
12+
report.info(s"Matched!")
13+
'{}
14+
case other =>
15+
report.errorAndAbort("woops, I did not match")
16+
}
17+
}
18+
}

tests/pos-macros/i18197b/Test.scala

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
trait Selector {
2+
extension [A](self: A) def at[B <: A]: B
3+
}
4+
5+
trait Config[A, B]
6+
7+
object Field {
8+
def const[A, B, FieldTpe](selector: Selector ?=> A => FieldTpe): Config[A, B] = ???
9+
}
10+
11+
final case class Example(int: Int)
12+
13+
@main def main = {
14+
// compiles just fine
15+
ReproMacro.readPath[Example, Example](Field.const(_.int))
16+
17+
// doesn't compile
18+
ReproMacro.readPath[Example, Example](Field.const(_.int.at[Int]))
19+
}

0 commit comments

Comments
 (0)