Skip to content

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 3 commits into from
May 21, 2021

Conversation

liufengyun
Copy link
Contributor

Fix #12344: tune splicing of default getters

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
Copy link
Contributor

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?

Copy link
Contributor

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.

Copy link
Contributor Author

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 ():

def test1e(using q: Quotes) = new C()()
def test2e(using q: Quotes) = C()()

Copy link
Contributor

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 if using isn't specified at call-site then it shouldn't map to the using param clause. Having the first () map to the using q clause breaks that rule.

Copy link
Contributor

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 as new 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".

Copy link
Contributor Author

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:

class C(using Int)
object C

Without prepending the constructor with(), the identifier C would be ambiguous (Scala 3 generailzes synthetic apply to all classes to avoid new).

For the example reported in #12344, the implicit parameter list comes after the synthetic empty parameter list (), and finally follows the default parameter list.

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()()
Copy link
Contributor

Choose a reason for hiding this comment

The 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-using param clause, it shouldn't be possible to specific two non-using clauses at call-site.

@liufengyun liufengyun requested a review from nicolasstucki May 17, 2021 13:44
@liufengyun
Copy link
Contributor Author

@nicolasstucki Could you have a look at this again?

@liufengyun liufengyun merged commit a956774 into scala:master May 21, 2021
@liufengyun liufengyun deleted the fix-12344 branch May 21, 2021 07:32
@Kordyjan Kordyjan added this to the 3.0.1 milestone Aug 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Can't create use new <constructor> of classes with leading given clauses
6 participants