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

Fix type inference involving wildcards #8129

Merged
merged 2 commits into from Jun 20, 2019
Merged

Conversation

adriaanm
Copy link
Contributor

@adriaanm adriaanm commented Jun 7, 2019

Use == instead of =:= because we're looking for occurs, not equality.

When we were using =:= to detect occurrences of type params in bounds,
we'd accidentally unify too much (e.g. on wildcards / other type vars).

Discovered while looking into why this doesn't type check:
java.util.stream.Stream.of(1,2,3).map(_.toString)

I noticed that there was cross talk between the type params of java.util.Function during type inference.

This partially regressed in #6492, but was actually wrong since the one with *** empty log message ***

Fix scala/bug#11558
Relates to scala/scala-dev#184

@scala-jenkins scala-jenkins added this to the 2.13.1 milestone Jun 7, 2019
@adriaanm adriaanm requested a review from retronym June 7, 2019 12:20
@adriaanm adriaanm changed the title Fix type infer regression introduced in scala/scala#6492 Fix type inference involving wildcards Jun 7, 2019
@retronym
Copy link
Member

retronym commented Jun 9, 2019

Confirming that the problematic example from scala/scala-dev#184 progresses here.

Before:

scala> "abc".chars.boxed.map(x => x.toString).collect(java.util.stream.Collectors.toList())
                               ^
       error: type mismatch;
        found   : Integer => String
        required: java.util.function.Function[_ >: Integer, _]

After:

scala> "abc".chars.boxed.map(x => x.toString).collect(java.util.stream.Collectors.toList())
res4: java.util.List[String] = [97, 98, 99]

@retronym
Copy link
Member

retronym commented Jun 9, 2019

Standalone test case that progresses:

trait F1[A, B] { def apply(a: A): B }; trait S[T] { def map[R](f: F1[_ >: T, _ <: R]): S[R] }; (f: S[Int]) => f.map(_.toString)

@SethTisue SethTisue added the release-notes worth highlighting in next release notes label Jun 9, 2019
@retronym
Copy link
Member

Pulling a few more threads in https://github.com/retronym/scala/tree/review/8129

Use == instead of =:= because we're looking for occurs, not equality.

When we were using =:= to detect occurrences of type params in bounds,
we'd accidentally unify too much (e.g. on wildcards / other type vars).

Discovered while looking into why this doesn't type check:
`java.util.stream.Stream.of(1,2,3).map(_.toString)`

(scala/bug 11558)

I noticed that there was cross talk between the type
params of java.util.Function during type inference.
Didn't take the typeSymbol-comparing route because
type constructor vars are too complicated to reason about
when moving constraints around -- just preserve old behavior.
@adriaanm
Copy link
Contributor Author

@retronym I incorporated a few strands of your review branch. LGTY?

@retronym retronym merged commit 3dc0d64 into scala:2.13.x Jun 20, 2019
@SethTisue
Copy link
Member

regression in overload resolution: scala/bug#11755

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release-notes worth highlighting in next release notes
Projects
None yet
4 participants