Skip to content

Implement for clauses for implied imports #6594

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 7 commits into from
Jun 3, 2019

Conversation

odersky
Copy link
Contributor

@odersky odersky commented Jun 1, 2019

Syntax:

import implied a.b.{for C, D[_]}

More details in import-implied.md.

odersky added 2 commits June 1, 2019 11:44
If we have a situation like this:

```
type A
type B <: A
implied a for A
implied b for B
```
we should recognize `b` to be more specific than `a`. Before this
commit that was not the case, since `a: A$`, `b: B$` and `B$` is not
a subtype of `A$`.
@odersky odersky force-pushed the change-implied-imports branch from b789e87 to 0f7e939 Compare June 1, 2019 09:58
odersky added 3 commits June 1, 2019 12:04
In a `for` clause of an implied imports, allow several bounds,
separated by commas. Writing
```
import a.b.{for C, D}
```
is equivalent to
```
import a.b.{for C | D}
```
but feels more natural.
Explain by-type imports on the doc page.
Also, add a test for wildcards in bounds.
Need to use normalizedCompatible instead of `<:<`.
@odersky odersky force-pushed the change-implied-imports branch from d10e0cb to 4a488c8 Compare June 1, 2019 12:42
Copy link
Contributor

@liufengyun liufengyun left a comment

Choose a reason for hiding this comment

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

LGTM

Some minor comments about the syntax:

  1. In the caseimport implied path.{for A, B}, it would be nicer to write import implied path._ for A, B

  2. In import implied path.{for A, B}, the keyword implied seems repetitive, as for already expresses the intent. It will be annoying if this is going to be the common case.

  3. Inside the brace, I feel something is missing before for. What about import implied path.{d, _ for A, B} ? I agree the _ is meaningless unless we allow { d for A, f for B}.

renamed <- reverseMapping.keys
denot <- pre.member(reverseMapping(renamed)).altsWith(_ is implicitFlag)
} yield {
yield {
val original = reverseMapping(renamed)
val ref = TermRef(pre, original, denot)
if (renamed == original) ref
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice for syntax 👍

Copy link
Member

Choose a reason for hiding this comment

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

Hum ... It doesn't look like valid Scala code to me, actually :-s Maybe with the indentation-based syntax, but that shouldn't be enabled there? Is the parser too lenient?

@odersky odersky mentioned this pull request Jun 3, 2019
6 tasks
@odersky
Copy link
Contributor Author

odersky commented Jun 3, 2019

Merging this for now, but we can continue the discussion about what's the best syntax to use.

@odersky odersky merged commit cc6cb05 into scala:master Jun 3, 2019
@liufengyun liufengyun deleted the change-implied-imports branch June 5, 2019 07:52
@biboudis biboudis added this to the 0.16 Tech Preview milestone Jun 7, 2019
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.

4 participants