-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Fix #12344: tune splicing of default getters #12353
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
Merged
Changes from all 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 @@ | ||
import scala.quoted.* | ||
|
||
class C(using q: Quotes)(i: Int = 1, f: q.reflect.Flags = q.reflect.Flags.EmptyFlags) | ||
|
||
def test1a(using q: Quotes) = new C() // error | ||
def test2a(using q: Quotes) = new C(1) // error | ||
def test3a(using q: Quotes) = new C(1, q.reflect.Flags.Lazy) // error | ||
def test4a(using q: Quotes) = new C(f = q.reflect.Flags.Lazy) // error | ||
|
||
def test1b(using q: Quotes) = C() // error | ||
def test2b(using q: Quotes) = C(1) // error | ||
def test3b(using q: Quotes) = C(1, q.reflect.Flags.Lazy) // error | ||
def test4b(using q: Quotes) = C(f = q.reflect.Flags.Lazy) // error | ||
|
||
def test1c(using q: Quotes) = new C(using q)() | ||
def test2c(using q: Quotes) = new C(using q)(1) | ||
def test3c(using q: Quotes) = new C(using q)(1, q.reflect.Flags.Lazy) | ||
def test4c(using q: Quotes) = new C(using q)(f = q.reflect.Flags.Lazy) | ||
|
||
def test1d(using q: Quotes) = C(using q)() | ||
def test2d(using q: Quotes) = C(using q)(1) | ||
def test3d(using q: Quotes) = C(using q)(1, q.reflect.Flags.Lazy) | ||
def test4d(using q: Quotes) = C(using q)(f = q.reflect.Flags.Lazy) | ||
|
||
def test1e(using q: Quotes) = new C()() | ||
def test2e(using q: Quotes) = C()() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similarly, I understand that these work now but that's part of the bug - these 2 lines shouldn't work. There's only one non- |
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.
Why is there an error with this one?
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.
It seems like it should compile.
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.
As you mentioned in #12344 (comment), for the default parameters to apply, we do need double
()
: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 goes against the design philosophy of
using
clauses though doesn't it? My understanding is that ifusing
isn't specified at call-site then it shouldn't map to theusing
param clause. Having the first()
map to theusing q
clause breaks that rule.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.
@japgolly I think there is no such mapping. It seems the ctor gets an initial empty param list that is not written, see the linked comment. The first explicit params in the call correspond to that one. This is perhaps more natural in Scala 2 where you expect auto-application and only one implicit at the end, so
new C
makes sense asnew C()(implicits)
. I see it must still be explicit in Scala 3 for case class: "A case class must have at least one non-implicit parameter list".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.
Given a definition like the following:
Without prepending the constructor with
()
, the identifierC
would be ambiguous (Scala 3 generailzes syntheticapply
to all classes to avoidnew
).For the example reported in #12344, the implicit parameter list comes after the
synthetic
empty parameter list()
, and finally follows the default parameter list.