Skip to content

Do not beta-reduce/eta-expand pattern splices with contextual function types #18198

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion compiler/src/dotty/tools/dotc/typer/Typer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3173,6 +3173,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 @@ -3957,7 +3958,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
sym.isConstructor
|| sym.matchNullaryLoosely
|| Feature.warnOnMigration(msg, tree.srcPos, version = `3.0`)
&& {
&& {
msg.actions
.headOption
.foreach(Rewrites.applyAction)
Expand Down Expand Up @@ -4021,6 +4022,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]))
}