Skip to content
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

Change wildcard given selectors #9949

Merged
merged 4 commits into from
Oct 6, 2020

Conversation

odersky
Copy link
Contributor

@odersky odersky commented Oct 6, 2020

Implements a syntax change for wildcard imports.
Instead of

import p.{given _}

write

import p.given

The same applies for wildcard given imports in braces: given _ is contracted to just given. Given-by-type imports remain unaffected: It's still

import p.{given T}

for those.

The rationale is that we should not make it needlessly hard to write wildcard given imports. The additional underscore after a given is not needed for disambiguation and clutters the code.

Implements a syntax change for wildcard imports.
Instead of
```scala
import p.{given _}
```
write
```scala
import p.given
```
The same applies for wildcard given imports in braces: `given _` is contracted to just `given`. Given-by-type imports remain unaffected: It's still
```scala
import p.{given T}
```
for those.

The rationale is that we should not make it needlessly hard to write wildcard given imports. The additional underscore after a `given` is not needed for disambiguation and clutters the code.
@odersky odersky added this to the 3.0.0-M1 milestone Oct 6, 2020
@odersky
Copy link
Contributor Author

odersky commented Oct 6, 2020

For now, both old and new syntax are supported. If this PR is merged, the old given _ syntax will be dropped after the next bootstrap.

@som-snytt
Copy link
Contributor

The only downside is that someone will have to adjust the StackOverflow answer for "how many uses of underscore are there in Scala 3?" Arguably the syntax could have been import p.{given ?}.

if in.token == USCORE then
in.nextToken()
ImportSelector(givenSelector()) // Let the selector span all of `given _`; needed for -Ytest-pickler
ImportSelector(givenSelectorId(start)) // Let the selector span all of `given _`; needed for -Ytest-pickler
Copy link
Member

Choose a reason for hiding this comment

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

Is this code path still needed for compatibility? If so, should we issue a deprecation warning here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So, far, we were changing syntax without warnings. But maybe we should change that now...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I tried to deprecate but that does not work for the current cycle since we still use given _ in bootstrap code. So we could deprecate at the earliest once 3.0 M1 is released. Or we just rip off the bandaid and disallow it altogether for M2.

Copy link
Member

Choose a reason for hiding this comment

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

We can do a bootstrap before M1 is released (and we probably should do one to make sure everything works OK with the new naming scheme)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK. We can deprecate again once that's done

@neko-kai
Copy link
Contributor

neko-kai commented Oct 6, 2020

@som-snytt already rejected alas... #8696

@odersky
Copy link
Contributor Author

odersky commented Oct 6, 2020

@neko-kai

`given ?` 

is not well-formed, since ? can be used only as an argument type to some other type. There was a test missing in the Parser to reject ? in this place. But you can use

given Any

as an alternative to just given.

@odersky odersky merged commit 99548bd into scala:master Oct 6, 2020
@odersky odersky deleted the change-given-wildcard-import branch October 6, 2020 16:56
@sake92
Copy link

sake92 commented Oct 7, 2020

I'm probably late to the party, but to me import p.given looks like I'm importing a member called given..
Wouldn't it be more intuitive to do similar to java's import static Abc.*? E.g.

import given p.T, p.MyType
import given p._, q._

No need to repeat given, given .. for every argument.

@nafg
Copy link

nafg commented Oct 8, 2020 via email

@griggt
Copy link
Collaborator

griggt commented Oct 8, 2020

@som-snytt
Copy link
Contributor

@sake92 if by late to the party you mean arriving just as drunken revelers stumble down the sidewalk discussing whether to deprecate first, then yes, pretty late. It began innocently with a few cocktails at https://contributors.scala-lang.org/t/proposed-syntax-change-import-given/4547

smarter added a commit to dotty-staging/dotty that referenced this pull request Oct 22, 2020
Was superceded by `given` in scala#9949.
smarter pushed a commit to dotty-staging/dotty that referenced this pull request Oct 22, 2020
Was superceded by `given` in scala#9949.
@Kordyjan Kordyjan modified the milestones: 3.0.0-M1, 3.0.0 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.

None yet

8 participants