-
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.
Support inline unapply extension methods
Fixes the computation of the inline unapply temporary unanimous unapply placeholder. Fixes #8577
- Loading branch information
1 parent
14f3793
commit 5fc9776
Showing
26 changed files
with
304 additions
and
8 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,11 @@ | ||
package i8577 | ||
|
||
import scala.quoted._ | ||
|
||
object Macro: | ||
opaque type StrCtx = StringContext | ||
def apply(ctx: StringContext): StrCtx = ctx | ||
def unapply(ctx: StrCtx): Option[StringContext] = Some(ctx) | ||
|
||
def implUnapply(sc: Expr[Macro.StrCtx], input: Expr[Int])(using Quotes): Expr[Option[Seq[Int]]] = | ||
'{ Some(Seq(${input})) } |
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 @@ | ||
package i8577 | ||
|
||
def main: Unit = | ||
extension (ctx: StringContext) def mac: Macro.StrCtx = Macro(ctx) | ||
extension (inline ctx: Macro.StrCtx) inline def unapplySeq(inline input: Int): Option[Seq[Int]] = | ||
${ implUnapply('ctx, 'input) } | ||
|
||
val mac"$x" = 1 | ||
assert(x == 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,11 @@ | ||
package i8577 | ||
|
||
import scala.quoted._ | ||
|
||
object Macro: | ||
opaque type StrCtx = StringContext | ||
def apply(ctx: StringContext): StrCtx = ctx | ||
def unapply(ctx: StrCtx): Option[StringContext] = Some(ctx) | ||
|
||
def implUnapply[U](sc: Expr[Macro.StrCtx], input: Expr[U])(using Type[U])(using Quotes): Expr[Option[Seq[U]]] = | ||
'{ Some(Seq(${input})) } |
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 @@ | ||
package i8577 | ||
|
||
def main: Unit = | ||
extension (ctx: StringContext) def mac: Macro.StrCtx = Macro(ctx) | ||
extension (inline ctx: Macro.StrCtx) inline def unapplySeq[U](inline input: U): Option[Seq[U]] = | ||
${ implUnapply('ctx, 'input) } | ||
|
||
val mac"$x" = 1 | ||
assert(x == 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,11 @@ | ||
package i8577 | ||
|
||
import scala.quoted._ | ||
|
||
object Macro: | ||
opaque type StrCtx = StringContext | ||
def apply(ctx: StringContext): StrCtx = ctx | ||
def unapply(ctx: StrCtx): Option[StringContext] = Some(ctx) | ||
|
||
def implUnapply[T](sc: Expr[Macro.StrCtx], input: Expr[T])(using Type[T])(using Quotes): Expr[Option[Seq[T]]] = | ||
'{ Some(Seq(${input})) } |
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 @@ | ||
package i8577 | ||
|
||
def main: Unit = | ||
extension (ctx: StringContext) def mac: Macro.StrCtx = Macro(ctx) | ||
extension [T] (inline ctx: Macro.StrCtx) inline def unapplySeq(inline input: T): Option[Seq[T]] = | ||
${ implUnapply('ctx, 'input) } | ||
|
||
val mac"$x" = 1 | ||
assert(x == 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,11 @@ | ||
package i8577 | ||
|
||
import scala.quoted._ | ||
|
||
object Macro: | ||
opaque type StrCtx = StringContext | ||
def apply(ctx: StringContext): StrCtx = ctx | ||
def unapply(ctx: StrCtx): Option[StringContext] = Some(ctx) | ||
|
||
def implUnapply[T](sc: Expr[Macro.StrCtx], input: Expr[T])(using Type[T])(using Quotes): Expr[Option[Seq[T]]] = | ||
'{ Some(Seq(${input})) } |
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 @@ | ||
package i8577 | ||
|
||
def main: Unit = | ||
extension (ctx: StringContext) def mac: Macro.StrCtx = Macro(ctx) | ||
extension [T] (inline ctx: Macro.StrCtx) inline def unapplySeq[U](inline input: T): Option[Seq[T]] = | ||
${ implUnapply('ctx, 'input) } | ||
|
||
val mac"$x" = 1 | ||
assert(x == 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,11 @@ | ||
package i8577 | ||
|
||
import scala.quoted._ | ||
|
||
object Macro: | ||
opaque type StrCtx = StringContext | ||
def apply(ctx: StringContext): StrCtx = ctx | ||
def unapply(ctx: StrCtx): Option[StringContext] = Some(ctx) | ||
|
||
def implUnapply[T, U](sc: Expr[Macro.StrCtx], input: Expr[U])(using Type[U])(using Quotes): Expr[Option[Seq[U]]] = | ||
'{ Some(Seq(${input})) } |
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 @@ | ||
package i8577 | ||
|
||
def main: Unit = | ||
extension (ctx: StringContext) def mac: Macro.StrCtx = Macro(ctx) | ||
extension [T] (inline ctx: Macro.StrCtx) inline def unapplySeq[U](inline input: U): Option[Seq[U]] = | ||
${ implUnapply('ctx, 'input) } | ||
|
||
val mac"$x" = 1 | ||
assert(x == 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,11 @@ | ||
package i8577 | ||
|
||
import scala.quoted._ | ||
|
||
object Macro: | ||
opaque type StrCtx = StringContext | ||
def apply(ctx: StringContext): StrCtx = ctx | ||
def unapply(ctx: StrCtx): Option[StringContext] = Some(ctx) | ||
|
||
def implUnapply[T, U](sc: Expr[Macro.StrCtx], input: Expr[(T, U)])(using Type[T], Type[U])(using Quotes): Expr[Option[Seq[(T, U)]]] = | ||
'{ Some(Seq(${input})) } |
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,12 @@ | ||
package i8577 | ||
|
||
def main: Unit = | ||
extension (ctx: StringContext) def mac: Macro.StrCtx = Macro(ctx) | ||
extension [T] (inline ctx: Macro.StrCtx) inline def unapplySeq[U](inline input: (T, U)): Option[Seq[(T, U)]] = | ||
${ implUnapply('ctx, 'input) } | ||
|
||
val mac"$x" = (1, 2) | ||
assert(x == (1, 2)) | ||
|
||
val mac"$y" = (1, "a") | ||
assert(y == (1, "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,11 @@ | ||
package i8577 | ||
|
||
import scala.quoted._ | ||
|
||
object Macro: | ||
opaque type StrCtx = StringContext | ||
def apply(ctx: StringContext): StrCtx = ctx | ||
def unapply(ctx: StrCtx): Option[StringContext] = Some(ctx) | ||
|
||
def implUnapply[T, U](sc: Expr[Macro.StrCtx], input: Expr[T | U])(using Type[T], Type[U])(using Quotes): Expr[Option[Seq[T | U]]] = | ||
'{ Some(Seq(${input})) } |
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 @@ | ||
package i8577 | ||
|
||
def main: Unit = | ||
extension (ctx: StringContext) def mac: Macro.StrCtx = Macro(ctx) | ||
extension [T] (inline ctx: Macro.StrCtx) inline def unapplySeq[U](inline input: T | U): Option[Seq[T | U]] = | ||
${ implUnapply('ctx, 'input) } | ||
|
||
val mac"$x" = 1 | ||
assert(x == 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,11 @@ | ||
package i8577 | ||
|
||
import scala.quoted._ | ||
|
||
object Macro: | ||
opaque type StrCtx = StringContext | ||
def apply(ctx: StringContext): StrCtx = ctx | ||
def unapply(ctx: StrCtx): Option[StringContext] = Some(ctx) | ||
|
||
def implUnapply[T, U](sc: Expr[Macro.StrCtx], input: Expr[T | U])(using Type[T], Type[U])(using Quotes): Expr[Option[Seq[T | U]]] = | ||
'{ Some(Seq(${input})) } |
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 @@ | ||
package i8577 | ||
|
||
def main: Unit = | ||
extension (ctx: StringContext) def mac: Macro.StrCtx = Macro(ctx) | ||
extension [T] (inline ctx: Macro.StrCtx) inline def unapplySeq[U](inline input: U | T): Option[Seq[T | U]] = | ||
${ implUnapply('ctx, 'input) } | ||
|
||
val mac"$x" = 1 | ||
assert(x == 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,15 @@ | ||
import scala.quoted._ | ||
|
||
object Macro: | ||
opaque type StrCtx = StringContext | ||
def apply(ctx: StringContext): StrCtx = ctx | ||
def unapply(ctx: StrCtx): Option[StringContext] = Some(ctx) | ||
|
||
extension (ctx: StringContext) def mac: Macro.StrCtx = Macro(ctx) | ||
extension (inline ctx: Macro.StrCtx) inline def unapplySeq(inline input: Int): Option[Seq[Int]] = | ||
Some(Seq(input)) | ||
|
||
@main def Test: Unit = | ||
val mac"$x" = 1 | ||
val y: Int = x | ||
assert(x == 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,15 @@ | ||
import scala.quoted._ | ||
|
||
object Macro: | ||
opaque type StrCtx = StringContext | ||
def apply(ctx: StringContext): StrCtx = ctx | ||
def unapply(ctx: StrCtx): Option[StringContext] = Some(ctx) | ||
|
||
extension (ctx: StringContext) def mac: Macro.StrCtx = Macro(ctx) | ||
extension (inline ctx: Macro.StrCtx) inline def unapplySeq[U](inline input: U): Option[Seq[U]] = | ||
Some(Seq(input)) | ||
|
||
@main def Test: Unit = | ||
val mac"$x" = 1 | ||
val y: Int = x | ||
assert(x == 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,15 @@ | ||
import scala.quoted._ | ||
|
||
object Macro: | ||
opaque type StrCtx = StringContext | ||
def apply(ctx: StringContext): StrCtx = ctx | ||
def unapply(ctx: StrCtx): Option[StringContext] = Some(ctx) | ||
|
||
extension (ctx: StringContext) def mac: Macro.StrCtx = Macro(ctx) | ||
extension [T] (inline ctx: Macro.StrCtx) inline def unapplySeq(inline input: T): Option[Seq[T]] = | ||
Some(Seq(input)) | ||
|
||
@main def Test: Unit = | ||
val mac"$x" = 1 | ||
val y: Int = x | ||
assert(x == 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,15 @@ | ||
import scala.quoted._ | ||
|
||
object Macro: | ||
opaque type StrCtx = StringContext | ||
def apply(ctx: StringContext): StrCtx = ctx | ||
def unapply(ctx: StrCtx): Option[StringContext] = Some(ctx) | ||
|
||
extension (ctx: StringContext) def mac: Macro.StrCtx = Macro(ctx) | ||
extension [T] (inline ctx: Macro.StrCtx) inline def unapplySeq[U](inline input: T): Option[Seq[T]] = | ||
Some(Seq(input)) | ||
|
||
@main def Test: Unit = | ||
val mac"$x" = 1 | ||
val y: Int = x | ||
assert(x == 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,19 @@ | ||
import scala.quoted._ | ||
|
||
object Macro: | ||
opaque type StrCtx = StringContext | ||
def apply(ctx: StringContext): StrCtx = ctx | ||
def unapply(ctx: StrCtx): Option[StringContext] = Some(ctx) | ||
|
||
extension (ctx: StringContext) def mac: Macro.StrCtx = Macro(ctx) | ||
extension [T] (inline ctx: Macro.StrCtx) inline def unapplySeq[U](inline input: (T, U)): Option[Seq[(T, U)]] = | ||
Some(Seq(input)) | ||
|
||
@main def Test: Unit = | ||
val mac"$x" = (1, 2) | ||
val x2: (Int, Int) = x | ||
assert(x == (1, 2)) | ||
|
||
val mac"$y" = (1, "a") | ||
val y2: (Int, String) = y | ||
assert(y == (1, "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,15 @@ | ||
import scala.quoted._ | ||
|
||
object Macro: | ||
opaque type StrCtx = StringContext | ||
def apply(ctx: StringContext): StrCtx = ctx | ||
def unapply(ctx: StrCtx): Option[StringContext] = Some(ctx) | ||
|
||
@main def Test: Unit = | ||
extension (ctx: StringContext) def mac: Macro.StrCtx = Macro(ctx) | ||
extension (inline ctx: Macro.StrCtx) inline def unapplySeq[U](inline input: U): Option[Seq[U]] = | ||
Some(Seq(input)) | ||
|
||
val mac"$x" = 1 | ||
val y: Int = x | ||
assert(x == 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,15 @@ | ||
import scala.quoted._ | ||
|
||
object Macro: | ||
opaque type StrCtx = StringContext | ||
def apply(ctx: StringContext): StrCtx = ctx | ||
def unapply(ctx: StrCtx): Option[StringContext] = Some(ctx) | ||
|
||
extension (ctx: StringContext) def mac: Macro.StrCtx = Macro(ctx) | ||
extension [T] (inline ctx: Macro.StrCtx) inline def unapplySeq[U](inline input: T | U): Option[Seq[T | U]] = | ||
Some(Seq(input)) | ||
|
||
@main def Test: Unit = | ||
val mac"$x" = 1 | ||
val y: Int = x | ||
assert(x == 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,15 @@ | ||
import scala.quoted._ | ||
|
||
object Macro: | ||
opaque type StrCtx = StringContext | ||
def apply(ctx: StringContext): StrCtx = ctx | ||
def unapply(ctx: StrCtx): Option[StringContext] = Some(ctx) | ||
|
||
extension (ctx: StringContext) def mac: Macro.StrCtx = Macro(ctx) | ||
extension [T] (inline ctx: Macro.StrCtx) inline def unapplySeq[U](inline input: U | T): Option[Seq[T | U]] = | ||
Some(Seq(input)) | ||
|
||
@main def Test: Unit = | ||
val mac"$x" = 1 | ||
val y: Int = x | ||
assert(x == 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._ | ||
|
||
object Macro: | ||
opaque type StrCtx = StringContext | ||
def apply(ctx: StringContext): StrCtx = ctx | ||
def unapply(ctx: StrCtx): Option[StringContext] = Some(ctx) | ||
|
||
extension (ctx: StringContext) def mac: Macro.StrCtx = Macro(ctx) | ||
extension (inline ctx: Macro.StrCtx) transparent inline def unapplySeq(inline input: String): Option[Seq[Any]] = | ||
Some(Seq(123)) | ||
|
||
@main def Test: Unit = | ||
"abc" match | ||
case mac"$x" => | ||
val y: Int = x | ||
assert(x == 123) |