Skip to content

Fix/#646 array addition #667

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 5 commits into from
Jun 22, 2015
Merged

Conversation

odersky
Copy link
Contributor

@odersky odersky commented Jun 18, 2015

Two fixes to implicits. First, a stratification of classTag methods in DottyPredef according to priority.
Second, and more importantly, we do not check for ambiguous implicits in viewExists.

Review by @adriaanm @DarkDimius

@odersky
Copy link
Contributor Author

odersky commented Jun 18, 2015

The first three commits are from #665 and #666

@odersky odersky force-pushed the fix/#646-array-addition branch from 80e2c36 to 4eeffb0 Compare June 19, 2015 14:23
@odersky
Copy link
Contributor Author

odersky commented Jun 19, 2015

Rebased to master

@DarkDimius
Copy link
Contributor

otherwise LGTM

odersky added 5 commits June 22, 2015 11:40
Previously, we'd see something like `? { :+: Int }`, which is confusing.
Now we see instead `? { :+ : Int }`.
Move addMode and friends to two decorators, one for Context, the other
for FreshContext. Implement behavior accordingly.

This avoids creating two contexts in situations like:

     c.fresh.setxploreTyperState.addMode(...)

Mow we can write

     c.fresh.addMode(...).setExploreTyperState

Because addMode returns a fresh context when applied to a fresh context.
Note that we specifically do not want virtual dispatch of addMode, that's
why it was moved to a decorator.

Also: removed mention of ".fresh: when just forllowed by an addMode, because
that one is redundant.
Test case in pending/run/array-addition.scala. The problem was that
implicit search failed to insert `genericArrayOps` around `Array()`.
The reason was that the implicit parameter for `genericArrayOps` was
ambiguous, multiple `classTag` methods matched the expected type
`ClassTag[?T >: Nothing]`.

Stratifying ClassTags in DottyPredef into layers according
to implicit priority avoids this problem. This is a temporary solution
until we have proper ClassTag handling in place.
Previously `viewExists(X, Y)` failed if there were ambiguous
implicit conversions from X to Y. This is too fragile, as
demonstrated by test case run/array-addition.scala. Here,
the `genericArrayOps` implicit was not inserted because its
result type `Array[?T]` was deemed to be incompatible with
`? { +: : ? }`. It was incompatible because there were multiple
implicits that added :+ to arrays of various element types.
But once `genericArrayOps` gets applied, the type parameter
`?T` of the array result is fixed, and the ambuity goes away.

The scenario shows that we should not test for ambiguous implicits
in viewExists. Such a test is fragile because it depends on the
progress of type inference when the test is made. It's preferable
to just test for any implicit conversion to exist and to check
for ambiguities later, when the implicit conversion is actually
applied. This has also the potential of speeding up implicit search
in situations where `viewExists` is called often (e.g. when coupled
with overloading resolution).
@odersky odersky force-pushed the fix/#646-array-addition branch from 6e6c6a8 to 74e9107 Compare June 22, 2015 09:42
@odersky
Copy link
Contributor Author

odersky commented Jun 22, 2015

Rebased to master

odersky added a commit that referenced this pull request Jun 22, 2015
@odersky odersky merged commit d2c96d0 into scala:master Jun 22, 2015
@allanrenucci allanrenucci deleted the fix/#646-array-addition branch December 14, 2017 19:21
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.

2 participants