Skip to content

Update reference for ommiting trait parameters #17988

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

Open
wants to merge 2 commits into
base: language-reference-stable
Choose a base branch
from

Conversation

Sporarum
Copy link
Contributor

@Sporarum Sporarum commented Jun 16, 2023

This is what I found out by experimenting, I did not look into the compiler to see what is actually done (which can be a good or bad thing)

Here is what I could come up with:
https://scastie.scala-lang.org/fEEqASMSTCWYuiZjDcRPbA

We can see there is a strong correlation between new T{} and extends T being allowed or disallowed.

I found it surprising that new Obj2{} is valid, while new Obj{} is not, given they are both valid with new ...()(){}, should I open an issue for that ?

@Sporarum Sporarum force-pushed the Sporarum-patch-trait-params branch from 6d7202a to 4bbcdea Compare June 16, 2023 11:08
@Sporarum Sporarum requested review from sjrd and bishabosha June 16, 2023 11:09
## Reference

For more information, see [Scala SIP 25](http://docs.scala-lang.org/sips/pending/trait-parameters.html).
TODO: Find which PR changed the behaviour, as this was changed between 3.2.2 and 3.2.1
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If someone with more knowledge of this area of the compiler could pinpoint this, I would be very grateful

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought this would be related to the PR that changes the constructor parameter encoding when parameters begin with a using clause

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one ?
#14840

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, I didn't check, but maybe this is the cause for a change?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO(@Sporarum): Check this

@bishabosha
Copy link
Member

this fixes it:

new Obj()(){}
case class Test(x: Int) extends Obj()()

@Sporarum
Copy link
Contributor Author

@bishabosha

this fixes it:

new Obj()(){}
case class Test(x: Int) extends Obj()()

Yes, that's what I mean by the following ^^'

I found it surprising that new Obj2{} is valid, while new Obj{} is not, given they are both valid with new ...()(){}, should I open an issue for that ?

But you'll note this is not my main problem with the current reference

@Sporarum
Copy link
Contributor Author

@bishabosha
You did not actually comment on the reference changes, what do you think ?

As always 1) correctness and 2) readability/clarity/etc

implicitly inserted as an additional parent with inferred arguments. For instance,
here's a variant of greetings where the addressee is a context parameter of type
`ImpliedName`:
If the trait `T` is parametrised such that `new T{}` would be a legal annonymous class creation, the "explicit extension required" rule does not apply, the parameters filled in as for the annonymous class:
Copy link
Member

@bishabosha bishabosha Jun 19, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the trait T is parametrised such that new T{}

I don't really like this because this is syntax sugar for the actual thing which is { class $anon extends T; new $anon}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I see, so it is actually the other way around ?

new T{ } is allowed because class _ extends T{ } is allowed ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm
Then the "obvious" spec would be "if all clauses can be inferred or called as (), they can all be ommitted", but this is not actually the case, as we can see from #18006

@Sporarum
Copy link
Contributor Author

(opened parens issue: #18006)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants