-
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.
Merge pull request #14203 from dotty-staging/fix-#14137
Add hint on -Xcheck-macro scope extrusion failure
- Loading branch information
Showing
5 changed files
with
63 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,23 @@ | ||
package x | ||
|
||
import scala.quoted._ | ||
|
||
object Macro: | ||
|
||
inline def genOp(inline f:Int): Int = ${ | ||
genOpImpl('f) | ||
} | ||
|
||
def genOpImpl(f: Expr[Int])(using Quotes): Expr[Int] = { | ||
|
||
def firstOp(): Expr[Int] = | ||
'{ | ||
var x=1 | ||
${secondOp('x,f)} | ||
} | ||
|
||
def secondOp(x:Expr[Int], y:Expr[Int]): Expr[Int] = | ||
'{ $x + $y } | ||
|
||
firstOp() | ||
} |
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,6 @@ | ||
package x | ||
|
||
object Main: | ||
|
||
def main(args: Array[String]):Unit = | ||
Macro.genOp(10) // error |
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,23 @@ | ||
package x | ||
|
||
import scala.quoted._ | ||
|
||
object Macro: | ||
|
||
inline def genOp(inline f:Int): Int = ${ | ||
genOpImpl('f) | ||
} | ||
|
||
def genOpImpl(f: Expr[Int])(using Quotes): Expr[Int] = { | ||
|
||
def firstOp()(using Quotes): Expr[Int] = | ||
'{ | ||
var x=1 | ||
${secondOp('x,f)} | ||
} | ||
|
||
def secondOp(x:Expr[Int], y:Expr[Int])(using Quotes): Expr[Int] = | ||
'{ $x + $y } | ||
|
||
firstOp() | ||
} |
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,6 @@ | ||
package x | ||
|
||
object Main: | ||
|
||
def main(args: Array[String]):Unit = | ||
Macro.genOp(10) |