-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Disallow phase inconsitent inline parameters
- Loading branch information
1 parent
7282a9b
commit 2ecdf91
Showing
63 changed files
with
561 additions
and
169 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
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,4 @@ | ||
package scala.quoted | ||
|
||
/** Stop code generation after an error has been reported */ | ||
class StopQuotedContext extends Throwable |
Large diffs are not rendered by default.
Oops, something went wrong.
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,30 @@ | ||
package scala.quoted | ||
package matching | ||
|
||
/** Literal sequence of literal constant value expressions */ | ||
object ValueSeq { | ||
|
||
/** Matches literal sequence of literal constant value expressions and return a sequence of values. | ||
* | ||
* Usage: | ||
* ```scala | ||
* inline def sum(args: Int*): Int = ${ sumExpr('args) } | ||
* def sumExpr(argsExpr: Expr[Seq[Int]])(given QuoteContext): Expr[Int] = argsExpr match | ||
* case ValueSeq(args) => | ||
* // args: Seq[Int] | ||
* ... | ||
* } | ||
* ``` | ||
*/ | ||
def unapply[T](expr: Expr[Seq[T]])(given valueOf: ValueOfExpr[T], qctx: QuoteContext): Option[Seq[T]] = expr match { | ||
case ExprSeq(elems) => | ||
elems.foldRight(Option(List.empty[T])) { (elem, acc) => | ||
(elem, acc) match { | ||
case (ValueOfExpr(value), Some(lst)) => Some(value :: lst) | ||
case (_, _) => None | ||
} | ||
} | ||
case _ => None | ||
} | ||
|
||
} |
File renamed without changes.
File renamed without changes.
15 changes: 13 additions & 2 deletions
15
tests/neg-macros/inline-macro-staged-interpreter/Macro_1.scala
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 |
---|---|---|
@@ -1,8 +1,8 @@ | ||
import quoted._ | ||
|
||
object Macro_1 { | ||
inline def foo(inline b: Boolean): Unit = ${fooImpl(b)} | ||
def fooImpl(b: Boolean)(given qctx: QuoteContext): Expr[Unit] = | ||
if (b) '{println("foo(true)")} | ||
inline def foo(inline b: Boolean): Unit = ${fooImpl('b)} | ||
def fooImpl(b: Expr[Boolean])(given qctx: QuoteContext): Expr[Unit] = | ||
if (b.value) '{println("foo(true)")} | ||
else { qctx.error("foo cannot be called with false"); '{ ??? } } | ||
} |
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,8 +1,8 @@ | ||
import quoted._ | ||
|
||
object Macro_1 { | ||
inline def foo(inline b: Boolean): Unit = ${fooImpl(b)} | ||
def fooImpl(b: Boolean)(given QuoteContext): Expr[Unit] = | ||
if (b) '{println("foo(true)")} | ||
inline def foo(inline b: Boolean): Unit = ${fooImpl('b)} | ||
def fooImpl(b: Expr[Boolean])(given QuoteContext): Expr[Unit] = | ||
if (b.value) '{println("foo(true)")} | ||
else ??? | ||
} |
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 |
---|---|---|
@@ -1,6 +1,13 @@ | ||
import scala.quoted._ | ||
|
||
object Test { | ||
inline def foo(inline x: Int): Int = ${fooImpl(x, 'x, '{ 'x }, '{ '{ 'x } })} | ||
inline def foo(inline x: Int): Int = ${ | ||
fooImpl( | ||
x, // error | ||
'x, | ||
'{ 'x }, // error | ||
'{ '{ 'x } } // error | ||
) | ||
} | ||
def fooImpl(a: Int, b: Expr[Int], c: Expr[(given QuoteContext) => Expr[Int]], d: Expr[(given QuoteContext) => Expr[(given QuoteContext) => Expr[Int]]]): Expr[Int] = ??? | ||
} |
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 @@ | ||
import scala.quoted._ | ||
|
||
inline def old(inline x: Int): Int = | ||
${ oldImpl(x) } // error | ||
|
||
private def oldImpl(x: Int): Expr[Int] = ??? | ||
|
||
inline def `new`(inline x: Int): Int = | ||
${ newImpl('x) } | ||
|
||
private def newImpl(x: Expr[Int]): Expr[Int] = ??? |
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
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
Oops, something went wrong.