-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Backport "Do not beta-reduce/eta-expand pattern splices with contextu…
…al function types" to LTS (#19127) Backports #18198 to the LTS branch. PR submitted by the release tooling. [skip ci]
- Loading branch information
Showing
4 changed files
with
46 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 = ??? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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])) | ||
} |