Skip to content

Commit

Permalink
Backport "Do not beta-reduce/eta-expand pattern splices with contextu…
Browse files Browse the repository at this point in the history
…al function types" to LTS (#19127)

Backports #18198 to the LTS branch.

PR submitted by the release tooling.
[skip ci]
  • Loading branch information
Kordyjan authored Dec 8, 2023
2 parents 8eedd71 + 79cec4b commit 7169347
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 0 deletions.
2 changes: 2 additions & 0 deletions compiler/src/dotty/tools/dotc/typer/Typer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3103,6 +3103,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
&& xtree.isTerm
&& !untpd.isContextualClosure(xtree)
&& !ctx.mode.is(Mode.Pattern)
&& !xtree.isInstanceOf[SplicePattern]
&& !ctx.isAfterTyper
&& !ctx.isInlineContext
then
Expand Down Expand Up @@ -3945,6 +3946,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
&& pt != SingletonTypeProto
&& pt != AssignProto
&& !ctx.mode.is(Mode.Pattern)
&& !tree.isInstanceOf[SplicePattern]
&& !ctx.isAfterTyper
&& !ctx.isInlineContext
then
Expand Down
7 changes: 7 additions & 0 deletions tests/pos-macros/i18197a.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import scala.quoted.*

def readPathMacro[A: Type, B: Type](expr: Expr[Any])(using Quotes) =
expr match
case '{ foo($y) } => y: Expr[Int ?=> Int]

def foo(x: Int ?=> Int): Any = ???
18 changes: 18 additions & 0 deletions tests/pos-macros/i18197b/Macro.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import scala.quoted.*

object ReproMacro {
inline def readPath[A, B](inline config: Config[A, B]) = ${ readPathMacro[A, B]('config) }

def readPathMacro[A: Type, B: Type](expr: Expr[Config[A, B]])(using Quotes) = {
import quotes.reflect.report

expr match {
case '{ Field.const[a, b, tpe]($selector) } =>
val selector2: Expr[Selector ?=> a => tpe] = selector
report.info(s"Matched!")
'{}
case other =>
report.errorAndAbort("woops, I did not match")
}
}
}
19 changes: 19 additions & 0 deletions tests/pos-macros/i18197b/Test.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
trait Selector {
extension [A](self: A) def at[B <: A]: B
}

trait Config[A, B]

object Field {
def const[A, B, FieldTpe](selector: Selector ?=> A => FieldTpe): Config[A, B] = ???
}

final case class Example(int: Int)

@main def main = {
// compiles just fine
ReproMacro.readPath[Example, Example](Field.const(_.int))

// doesn't compile
ReproMacro.readPath[Example, Example](Field.const(_.int.at[Int]))
}

0 comments on commit 7169347

Please sign in to comment.