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 upper bound constraints, that are higher-kinded #16744

Merged
merged 1 commit into from
Jan 23, 2023

Conversation

dwijnand
Copy link
Member

When recording an upper bound, when it's a some higher-kinded type
variable applied to some type arguments, TypeComparer was re-applying
the type arguments to the type parameter (the type variable's origin).
Meaning that the instantiation of the type variable won't reflect in the
upper bound.

See the error message: F$1[Int] correctly appears as the lower bound,
but F$1[Int] isn't the upper bound, F[Int] is, which is the original
type parameter, in Foo.Bar.apply[F](..).

-- [E007] Type Mismatch Error: i12478.scala:8:13 -------------------------------
8 |      Foo.Bar(fu1)
  |      ^^^^^^^^^^^^
  |Found:    Foo.Bar[F$1]
  |Required: Foo[T1]
  |
  |where:    F$1 is a type in method id1 with bounds <: [_] =>> Any
  |          T1  is a type in method id1 with bounds >: F$1[Int] and <: F[Int]
  |
  | longer explanation available when compiling with `-explain`
-- [E007] Type Mismatch Error: i12478.scala:18:13 ------------------------------
18 |      Foo.Bar(fu3)
   |      ^^^^^^^^^^^^
   |Found:    Foo.Bar[F$2]
   |Required: Foo[T3]
   |
   |where:    F$2 is a type in method id3 with bounds <: [_] =>> Any
   |          T3  is a type in method id3 with bounds >: F$2[Int] and <: F[Int]
   |
   | longer explanation available when compiling with `-explain`

@dwijnand
Copy link
Member Author

I'd already encountered this bug and fix in my AssumeInfo PR (#15928) but I found it to be the cause of #12478, so we can land this fix earlier.

@dwijnand dwijnand marked this pull request as ready for review January 22, 2023 21:30
@dwijnand dwijnand requested a review from odersky January 22, 2023 21:30
When recording an upper bound, when it's a some higher-kinded type
variable applied to some type arguments, TypeComparer was re-applying
the type arguments to the type parameter (the type variable's origin).
Meaning that the instantiation of the type variable won't reflect in the
upper bound.

See the error message: `F$1[Int]` correctly appears as the lower bound,
but `F$1[Int]` isn't the upper bound, `F[Int]` is, which is the original
type parameter, in `Foo.Bar.apply[F](..)`.

    -- [E007] Type Mismatch Error: i12478.scala:8:13 -------------------------------
    8 |      Foo.Bar(fu1)
      |      ^^^^^^^^^^^^
      |Found:    Foo.Bar[F$1]
      |Required: Foo[T1]
      |
      |where:    F$1 is a type in method id1 with bounds <: [_] =>> Any
      |          T1  is a type in method id1 with bounds >: F$1[Int] and <: F[Int]
      |
      | longer explanation available when compiling with `-explain`
    -- [E007] Type Mismatch Error: i12478.scala:18:13 ------------------------------
    18 |      Foo.Bar(fu3)
       |      ^^^^^^^^^^^^
       |Found:    Foo.Bar[F$2]
       |Required: Foo[T3]
       |
       |where:    F$2 is a type in method id3 with bounds <: [_] =>> Any
       |          T3  is a type in method id3 with bounds >: F$2[Int] and <: F[Int]
       |
       | longer explanation available when compiling with `-explain`
@odersky odersky merged commit 3800c91 into scala:main Jan 23, 2023
@dwijnand dwijnand deleted the gadt-better branch January 23, 2023 15:51
@Kordyjan Kordyjan added this to the 3.3.1 milestone Aug 1, 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.

GADT pattern matching fails to infer type equations
3 participants