-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace quoted type variables in signature of HOAS pattern result
To be able to construct the lambda returned by the HOAS pattern we need: first resolve the type variables and then use the result to construct the signature of the lambdas. To simplify this transformation, `QuoteMatcher` returns a `Seq[MatchResult]` instead of an untyped `Tuple` containing `Expr[?]`. The tuple is created once we have accumulated and processed all extracted values. Fixes #15165
- Loading branch information
1 parent
dbdca17
commit 20174d7
Showing
8 changed files
with
122 additions
and
34 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
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,9 @@ | ||
import scala.quoted.* | ||
|
||
inline def valToFun[T](inline expr: T): T = | ||
${ impl('expr) } | ||
|
||
def impl[T: Type](expr: Expr[T])(using quotes: Quotes): Expr[T] = | ||
expr match | ||
case '{ { val ident = ($a: α); $rest(ident): T } } => | ||
'{ { (y: α) => $rest(y) }.apply(???) } |
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,4 @@ | ||
def test = valToFun { | ||
val a: Int = 1 | ||
a + 1 | ||
} |
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,16 @@ | ||
import scala.quoted.* | ||
|
||
inline def valToFun[T](inline expr: T): T = | ||
${ impl('expr) } | ||
|
||
def impl[T: Type](expr: Expr[T])(using quotes: Quotes): Expr[T] = | ||
expr match | ||
case '{ { val ident = ($a: α); $rest(ident): T } } => | ||
'{ | ||
{ (y: α) => | ||
${ | ||
val bound = '{ ${ rest }(y) } | ||
Expr.betaReduce(bound) | ||
} | ||
}.apply($a) | ||
} |
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,4 @@ | ||
def test = valToFun { | ||
val a: Int = 1 | ||
a + 1 | ||
} |
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,9 @@ | ||
import scala.quoted.* | ||
|
||
inline def valToFun[T](inline expr: T): T = | ||
${ impl('expr) } | ||
|
||
def impl[T: Type](expr: Expr[T])(using quotes: Quotes): Expr[T] = | ||
expr match | ||
case '{ type α; { val ident = ($a: `α`); $rest(ident): `α` & T } } => | ||
'{ { (y: α) => $rest(y) }.apply(???) } |
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,4 @@ | ||
def test = valToFun { | ||
val a: Int = 1 | ||
a + 1 | ||
} |