-
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.
Remove NamedArg from inlined arguments
Fixes #17227
- Loading branch information
1 parent
bcaa1ca
commit 0b346f0
Showing
4 changed files
with
48 additions
and
5 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,22 @@ | ||
import scala.quoted.* | ||
|
||
inline def foo(f: Int => Int): Int => Int = ${impl('f)} | ||
inline def bar(inline f: Int => Int): Int => Int = ${impl('f)} | ||
inline def baz(inline f: (Int => Int)*): Int => Int = ${impl2('f)} | ||
|
||
def impl(f: Expr[Int => Int])(using Quotes): Expr[Int => Int] = | ||
assertNoNamedArgs(f) | ||
'{identity} | ||
|
||
def impl2(f: Expr[Seq[Int => Int]])(using Quotes): Expr[Int => Int] = | ||
assertNoNamedArgs(f) | ||
'{identity} | ||
|
||
def assertNoNamedArgs(expr: Expr[Any])(using Quotes): Unit = | ||
import quotes.reflect.* | ||
new TreeTraverser { | ||
override def traverseTree(tree: Tree)(owner: Symbol): Unit = tree match | ||
case _: NamedArg => | ||
report.throwError(s"Unexpected NamedArg after inlining: ${tree}", tree.pos) | ||
case _ => traverseTreeChildren(tree)(owner) | ||
}.traverseTree(expr.asTerm)(Symbol.spliceOwner) |
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 @@ | ||
def g(i: Int): Int = i | ||
|
||
def test = | ||
foo(f = g) | ||
bar(f = g) | ||
baz(f = g) |
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,10 @@ | ||
inline def foo(f: Int => Int): Int => Int = f | ||
inline def bar(inline f: Int => Int): Int => Int = f | ||
inline def baz(f: (Int => Int)*): Int => Int = f.head | ||
|
||
def g(i: Int): Int = i | ||
|
||
def test = | ||
foo(f = g) | ||
bar(f = g) | ||
baz(f = g) |