-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Add toExprOfTuple in scala.quoted #7037
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
nicolasstucki
merged 3 commits into
scala:master
from
dotty-staging:add-seq-to-expr-tuple
Aug 19, 2019
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,26 @@ | ||
() | ||
(1) | ||
(1,2) | ||
(1,2,3) | ||
(1,2,3,4) | ||
(1,2,3,4,5) | ||
(1,2,3,4,5,6) | ||
(1,2,3,4,5,6,7) | ||
(1,2,3,4,5,6,7,8) | ||
(1,2,3,4,5,6,7,8,9) | ||
(1,2,3,4,5,6,7,8,9,10) | ||
(1,2,3,4,5,6,7,8,9,10,11) | ||
(1,2,3,4,5,6,7,8,9,10,11,12) | ||
(1,2,3,4,5,6,7,8,9,10,11,12,13) | ||
(1,2,3,4,5,6,7,8,9,10,11,12,13,14) | ||
(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15) | ||
(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16) | ||
(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17) | ||
(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18) | ||
(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19) | ||
(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20) | ||
(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21) | ||
(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22) | ||
(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23) | ||
(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24) | ||
(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25) |
This file contains hidden or 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,17 @@ | ||
|
||
import scala.quoted._ | ||
|
||
object Test { | ||
implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) | ||
def main(args: Array[String]): Unit = { | ||
for (n <- 0 to 25) { | ||
prev = 0 | ||
println(run { Seq.fill(n)('{next}).toExprOfTuple }) | ||
} | ||
} | ||
var prev = 0 | ||
def next: Int = { | ||
prev += 1 | ||
prev | ||
} | ||
} |
This file contains hidden or 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,14 @@ | ||
import scala.quoted._ | ||
|
||
object Macro { | ||
inline def t2[T0, T1](t0: T0, t1: T1)/*: (T0, T1) */ = ${ impl2('{t0}, '{t1}) } | ||
|
||
def impl2[T0: Type, T1: Type](t0: Expr[T0], t1: Expr[T1]) given (qctx: QuoteContext)/*: Expr[(T0, T1)]*/ = { | ||
import qctx.tasty._ | ||
import util._ | ||
|
||
val seq = List(t0, t1) | ||
val res = seq.toExprOfTuple | ||
res//.cast[(T0, T1)] | ||
} | ||
} |
This file contains hidden or 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,5 @@ | ||
object Test extends App { | ||
val t2 = Macro.t2(23, "foo") | ||
val t2a/*: (Int, String)*/ = t2 | ||
assert(t2a == (23, "foo")) | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test should be in
tests/run-macros
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That fixed it. It was probably a bad interaction with the non bootstrapped compiler.