Skip to content

Fix #11234: Avoid cycles in unifying F-bounded type parameters #11237

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 1 commit into from
Mar 4, 2021

Conversation

liufengyun
Copy link
Contributor

@liufengyun liufengyun commented Jan 28, 2021

Fix #11234

In tests/pos/11234.scala, we have the following F-bounded constraints:

bounds =
A0 <: Foo[LazyRef(A0)]
A <: Foo[LazyRef(A)]
ordering =
A <: A0

As Foo[T] is non-variant, at some point we will add A0 <: A, it
will trigger unification of A0 and A. The unification will call
Foo[A0].&(Foo[A]), which in turn calls TypeComparer.glb(Foo[A0], Foo[A]). The call glb(Foo[A0], Foo[A]) in a fresh TypeComparer
will in turn add A0 <: A thus trigger the unification again.

We need to perform substitution before merging the bounds.

In tests/pos/11234.scala, we have the following F-bounded constraints:

    bounds =
	A0 <: Foo[LazyRef(A0)]
	A <: Foo[LazyRef(A)]
    ordering =
	A <: A0

As `Foo[T]` is non-variant, at some point we will add `A0 <: A`, it
will trigger unification of `A0` and `A`. The unification will call
`Foo[A0].&(Foo[A])`, which in turn calls `TypeComparer.glb(Foo[A0],
Foo[A])`.  The call `glb(Foo[A0], Foo[A])` in a fresh TypeComparer
will in turn add `A0 <: A` thus trigger the unification again.

We need to perform substitution before merge the bounds.
@liufengyun liufengyun changed the title Trial: avoid cycles in unifying F-bounded type parameters Fix #11234: Avoid cycles in unifying F-bounded type parameters Mar 4, 2021
@liufengyun liufengyun marked this pull request as ready for review March 4, 2021 11:05
@liufengyun liufengyun requested a review from odersky March 4, 2021 11:53
@liufengyun liufengyun assigned odersky and unassigned liufengyun Mar 4, 2021
@odersky
Copy link
Contributor

odersky commented Mar 4, 2021

Nice fix!

@odersky odersky merged commit 951a726 into scala:master Mar 4, 2021
@odersky odersky deleted the fix-11234 branch March 4, 2021 16:41
@Kordyjan Kordyjan added this to the 3.0.0 milestone 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.

Incorrect type inference for F-bounds
3 participants