forked from scala/scala3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix scala#7142: Detect scope extrusions in macros and run
- Loading branch information
1 parent
e7e364a
commit 7831691
Showing
21 changed files
with
171 additions
and
16 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
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 @@ | ||
package macros | ||
import scala.quoted._ | ||
|
||
def oops(given QuoteContext) = { | ||
var v = '{0}; | ||
val q = '{ (x: Int) => ${ v = '{x}; v } } | ||
'{$q($v)} | ||
} | ||
inline def test = ${oops} |
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 @@ | ||
|
||
object Test { | ||
macros.test // 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,8 @@ | ||
package macros | ||
import scala.quoted._ | ||
import scala.util.control.NonLocalReturns._ | ||
|
||
def oops(given QuoteContext): Expr[Int] = | ||
returning('{ { (x: Int) => ${ throwReturn('x) }} apply 0 }) | ||
|
||
inline def test = ${oops} |
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 @@ | ||
|
||
object Test { | ||
macros.test // 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,9 @@ | ||
package macros | ||
import scala.quoted._ | ||
|
||
def oops(given QuoteContext) = { | ||
var v = '{0}; | ||
val q = '{ val x: Int = 8; ${ v = '{x}; v } } | ||
v | ||
} | ||
inline def test = ${oops} |
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 @@ | ||
|
||
object Test { | ||
macros.test // 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,9 @@ | ||
package macros | ||
import scala.quoted._ | ||
|
||
def oops(given QuoteContext) = { | ||
var v = '{0}; | ||
val q = '{ ??? match { case x => ${ v = '{x}; v } } } | ||
v | ||
} | ||
inline def test = ${oops} |
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 @@ | ||
|
||
object Test { | ||
macros.test // 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,9 @@ | ||
package macros | ||
import scala.quoted._ | ||
|
||
def oops(given QuoteContext) = { | ||
var v = '{0}; | ||
val q = '{ def x: Int = 8; ${ v = '{x}; v } } | ||
v | ||
} | ||
inline def test = ${oops} |
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 @@ | ||
|
||
object Test { | ||
macros.test // 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,9 @@ | ||
package macros | ||
import scala.quoted._ | ||
|
||
def oops(given QuoteContext) = { | ||
var v = '{0}; | ||
val q = '{ def f(x: Int): Int = ${ v = '{x}; v } } | ||
v | ||
} | ||
inline def test = ${oops} |
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 @@ | ||
|
||
object Test { | ||
macros.test // 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,9 @@ | ||
package macros | ||
import scala.quoted._ | ||
|
||
def oops(given QuoteContext) = { | ||
var v = '{}; | ||
val q = '{ var x: Int = 8; ${ v = '{x = 9}; v } } | ||
v | ||
} | ||
inline def test = ${oops} |
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 @@ | ||
|
||
object Test { | ||
macros.test // 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
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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
foo Location(List(Test$, loc1)) | ||
foo Location(List(Test$, main)) | ||
foo Location(List(Test$, main)) | ||
foo Location(List(Test$, main, bar)) | ||
foo Location(List(Test$, main, bar, baz)) | ||
foo Location(List(Test$, main, f, $anonfun)) | ||
foo Location(List(Test$, loc1, macro$1)) | ||
foo Location(List(Test$, main, macro$2)) | ||
foo Location(List(Test$, main, macro$3)) | ||
foo Location(List(Test$, main, bar, macro$4)) | ||
foo Location(List(Test$, main, bar, baz, macro$5)) | ||
foo Location(List(Test$, main, f, $anonfun, macro$6)) |
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,13 @@ | ||
import scala.quoted._ | ||
import scala.quoted.staging._ | ||
import scala.util.control.NonLocalReturns._ | ||
|
||
object Test { | ||
given Toolbox = Toolbox.make(getClass.getClassLoader) | ||
def main(args: Array[String]): Unit = | ||
try run {returning('{ { (x: Int) => ${ throwReturn('x) }} apply 0 })} | ||
catch { | ||
case ex: dotty.tools.dotc.reporting.diagnostic.messages.Error => | ||
assert(ex.getMessage == "While expanding a macro, a reference to value x was used outside the scope where it was defined", ex.getMessage) | ||
} | ||
} |