-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Fix usage of outer type argument in extension inline unapply #15189
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
Closed
Closed
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
8bc5e73
fix bug with inline extension methods
bc8dc65
special-case inline extension unapplySeq (including polymorphic varia…
1ca06a4
Merge remote-tracking branch 'origin/main'
99873a2
comment uncertain line
c0439c3
fix another bug
3f5c7cf
Merge branch 'lampepfl:main' into main
gorilskij 11a3f9f
add test case
ac390f3
Merge remote-tracking branch 'origin/main'
04bd41e
add (non-working) macro test case
ea9b46f
add proper test cases
e7a74e4
Merge branch 'non-working-test-case'
2c6e613
minor change
26e4dca
implement a fix
cad3203
Merge branch 'special-case-inline-unapplySeq' into extension-outer-ty…
e9965a1
uncomment relevant test case
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 | ||
|
||
import scala.quoted._ | ||
|
||
object MacroA: | ||
opaque type StringContext = scala.StringContext | ||
def apply(ctx: scala.StringContext): StringContext = ctx | ||
def unapply(ctx: StringContext): Option[scala.StringContext] = Some(ctx) | ||
|
||
def implUnapplyA(sc: Expr[MacroB.StringContext], input: Expr[Int]) | ||
(using Quotes): Expr[Option[Seq[Int]]] = | ||
'{ Some(Seq(${input})) } |
This file contains hidden or 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 | ||
|
||
import scala.quoted._ | ||
|
||
object MacroB: | ||
opaque type StringContext = scala.StringContext | ||
def apply(ctx: scala.StringContext): StringContext = ctx | ||
def unapply(ctx: StringContext): Option[scala.StringContext] = Some(ctx) | ||
|
||
def implUnapplyB[U](sc: Expr[MacroB.StringContext], input: Expr[U]) | ||
(using Type[U])(using Quotes): Expr[Option[Seq[U]]] = | ||
'{ Some(Seq(${input})) } |
This file contains hidden or 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 | ||
|
||
import scala.quoted._ | ||
|
||
object MacroC: | ||
opaque type StringContext = scala.StringContext | ||
def apply(ctx: scala.StringContext): StringContext = ctx | ||
def unapply(ctx: StringContext): Option[scala.StringContext] = Some(ctx) | ||
|
||
def implUnapplyC[T](sc: Expr[MacroC.StringContext], input: Expr[T]) | ||
(using Type[T])(using Quotes): Expr[Option[Seq[T]]] = | ||
'{ Some(Seq(${input})) } |
This file contains hidden or 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 | ||
|
||
import scala.quoted._ | ||
|
||
object MacroD: | ||
opaque type StringContext = scala.StringContext | ||
def apply(ctx: scala.StringContext): StringContext = ctx | ||
def unapply(ctx: StringContext): Option[scala.StringContext] = Some(ctx) | ||
|
||
def implUnapplyD[T](sc: Expr[MacroD.StringContext], input: Expr[T]) | ||
(using Type[T])(using Quotes): Expr[Option[Seq[T]]] = | ||
'{ Some(Seq(${input})) } |
This file contains hidden or 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 | ||
|
||
import scala.quoted._ | ||
|
||
object MacroE: | ||
opaque type StringContext = scala.StringContext | ||
def apply(ctx: scala.StringContext): StringContext = ctx | ||
def unapply(ctx: StringContext): Option[scala.StringContext] = Some(ctx) | ||
|
||
def implUnapplyE[T, U](sc: Expr[MacroE.StringContext], input: Expr[U]) | ||
(using Type[U])(using Quotes): Expr[Option[Seq[U]]] = | ||
'{ Some(Seq(${input})) } |
This file contains hidden or 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 | ||
|
||
import scala.quoted._ | ||
|
||
object MacroF: | ||
opaque type StringContext = scala.StringContext | ||
def apply(ctx: scala.StringContext): StringContext = ctx | ||
def unapply(ctx: StringContext): Option[scala.StringContext] = Some(ctx) | ||
|
||
def implUnapplyF[T, U](sc: Expr[MacroF.StringContext], input: Expr[(T, U)]) | ||
(using Type[T], Type[U])(using Quotes): Expr[Option[Seq[(T, U)]]] = | ||
'{ Some(Seq(${input})) } |
This file contains hidden or 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 | ||
|
||
import scala.quoted._ | ||
|
||
object MacroG: | ||
opaque type StringContext = scala.StringContext | ||
def apply(ctx: scala.StringContext): StringContext = ctx | ||
def unapply(ctx: StringContext): Option[scala.StringContext] = Some(ctx) | ||
|
||
def implUnapplyG[T, U](sc: Expr[MacroG.StringContext], input: Expr[T | U]) | ||
(using Type[T], Type[U])(using Quotes): Expr[Option[Seq[T | U]]] = | ||
'{ Some(Seq(${input})) } |
This file contains hidden or 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,164 @@ | ||
package i8577 | ||
|
||
def main: Unit = { | ||
{ | ||
extension (ctx: StringContext) def macroA: MacroB.StringContext = MacroB(ctx) | ||
extension (inline ctx: MacroB.StringContext) inline def unapplySeq(inline input: Int): Option[Seq[Int]] = | ||
${implUnapplyA('ctx, 'input)} | ||
|
||
val macroA"$xA" = 1 | ||
} | ||
|
||
{ | ||
extension (ctx: StringContext) def macroB: MacroB.StringContext = MacroB(ctx) | ||
extension (inline ctx: MacroB.StringContext) inline def unapplySeq[U](inline input: U): Option[Seq[U]] = | ||
${ implUnapplyB('ctx, 'input) } | ||
|
||
val macroB"$xB" = 2 | ||
} | ||
|
||
{ | ||
extension (ctx: StringContext) def macroC: MacroC.StringContext = MacroC(ctx) | ||
extension [T] (inline ctx: MacroC.StringContext) inline def unapplySeq(inline input: T): Option[Seq[T]] = | ||
${ implUnapplyC('ctx, 'input) } | ||
|
||
val macroC"$xC" = 3 | ||
} | ||
|
||
{ | ||
extension (ctx: StringContext) def macroD: MacroD.StringContext = MacroD(ctx) | ||
extension [T] (inline ctx: MacroD.StringContext) inline def unapplySeq[U](inline input: T): Option[Seq[T]] = | ||
${ implUnapplyD('ctx, 'input) } | ||
|
||
// miscompilation | ||
// val macroD"$xD" = 4 | ||
} | ||
|
||
{ | ||
extension (ctx: StringContext) def macroE: MacroE.StringContext = MacroE(ctx) | ||
extension [T] (inline ctx: MacroE.StringContext) inline def unapplySeq[U](inline input: U): Option[Seq[U]] = | ||
${ implUnapplyE('ctx, 'input) } | ||
|
||
val macroE"$xE" = 5 | ||
} | ||
|
||
{ | ||
extension (ctx: StringContext) def macroF: MacroF.StringContext = MacroF(ctx) | ||
extension [T] (inline ctx: MacroF.StringContext) inline def unapplySeq[U](inline input: (T, U)): Option[Seq[(T, U)]] = | ||
${ implUnapplyF('ctx, 'input) } | ||
|
||
val macroF"$xF" = (6, 7) | ||
|
||
// miscompilation | ||
// val macroF"$xF" = (6, "7") | ||
} | ||
|
||
{ | ||
extension (ctx: StringContext) def macroG: MacroG.StringContext = MacroG(ctx) | ||
extension [T] (inline ctx: MacroG.StringContext) inline def unapplySeq[U](inline input: T | U): Option[Seq[T | U]] = | ||
${ implUnapplyG('ctx, 'input) } | ||
|
||
// compiler error | ||
// val macroG"$xG" = 8 | ||
} | ||
} | ||
|
||
// { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is this section commented out? |
||
// // B | ||
// object F2 | ||
// extension (o: F2.type) inline def unapplySeq[T](inline x: T) = Some(Seq(x)) | ||
// | ||
// val F2(x) = 16 | ||
// println(s"F2: $x") | ||
// } | ||
// | ||
// { | ||
// // C | ||
// object F1 | ||
// extension [T] (o: F1.type) inline def unapplySeq(inline x: T) = Some(Seq(x)) | ||
// | ||
// val F1(x) = 15 | ||
// println(s"F1: $x") | ||
// } | ||
// | ||
// { | ||
// // D | ||
// object F4b | ||
// extension [T] (o: F4b.type) inline def unapplySeq[U](inline x: T) = Some(Seq(x)) | ||
// | ||
// val F4b(x) = 18.2 | ||
// println(s"F4b: $x") | ||
// } | ||
// | ||
// { | ||
// // E | ||
// object F4b | ||
// extension [T] (o: F4b.type) inline def unapplySeq[U](inline x: U) = Some(Seq(x)) | ||
// | ||
// val F4b(x) = 18.2 | ||
// println(s"F4b: $x") | ||
// } | ||
// | ||
// { | ||
// // F | ||
// object F4d | ||
// extension [T] (o: F4d.type) inline def unapplySeq[U](inline x: (T, U)) = Some(Seq(x)) | ||
// | ||
// val F4d(x) = (18.4, 18.5) | ||
// println(s"F4d: $x") | ||
// } | ||
// | ||
// { | ||
// // G | ||
// object H1 | ||
// extension (inline o: H1.type) inline def unapplySeq(inline x: Int) = Some(Seq(x)) | ||
// | ||
// val H1(x) = 23 | ||
// println(s"H1: $x") | ||
// } | ||
// | ||
// { | ||
// // H | ||
// object H2 | ||
// extension (inline o: H2.type) inline def unapplySeq[T](inline x: T) = Some(Seq(x)) | ||
// | ||
// val H2(x) = 24 | ||
// println(s"H2: $x") | ||
// } | ||
// | ||
// { | ||
// // I | ||
// object H2 | ||
// extension [T] (inline o: H2.type) inline def unapplySeq(inline x: T) = Some(Seq(x)) | ||
// | ||
// val H2(x) = 24 | ||
// println(s"H2: $x") | ||
// } | ||
// | ||
// { | ||
// // J | ||
// object H2 | ||
// extension [T] (inline o: H2.type) inline def unapplySeq[U](inline x: T) = Some(Seq(x)) | ||
// | ||
// val H2(x) = 24 | ||
// println(s"H2: $x") | ||
// } | ||
// | ||
// { | ||
// // K | ||
// object H2 | ||
// extension [T] (inline o: H2.type) inline def unapplySeq[U](inline x: U) = Some(Seq(x)) | ||
// | ||
// val H2(x) = 24 | ||
// println(s"H2: $x") | ||
// } | ||
// | ||
// { | ||
// // L | ||
// object H2 | ||
// extension [T] (inline o: H2.type) inline def unapplySeq[U](inline x: (T, U)) = Some(Seq(x)) | ||
// | ||
// val H2(x) = (24, "a") | ||
// println(s"H2: $x") | ||
// } | ||
//} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the intentional that this should not compile?
If so, you could create a separate netagive test in
tests/neg/