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
9e7ec22
commit b8ee2a6
Showing
21 changed files
with
165 additions
and
1 deletion.
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 @@ | ||
package macros | ||
import scala.quoted._ | ||
|
||
def oops(given QuoteContext) = { | ||
var v = '{0}; | ||
val q = '{ (x: Int) => ${ v = '{x}; v } } // error | ||
'{$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 | ||
} |
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 }) // error | ||
|
||
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 | ||
} |
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 } } // error | ||
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 | ||
} |
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 } } } // error | ||
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 | ||
} |
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 } } // error | ||
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 | ||
} |
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 } } // error | ||
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 | ||
} |
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 = '{ class Foo(x: Int) { ${ v = 'x; '{} } }} // error | ||
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 | ||
} |
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 = '{ class Foo { val x = 3; ${ v = 'x; '{} } }} // error | ||
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 | ||
} |
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 } } // error | ||
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 | ||
} |
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 @@ | ||
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 if ex.getMessage == "x was used outside the scope where it was defined" => // OK | ||
} | ||
} |