Skip to content

Method type parameter not inferred when given a dependent type #12803

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

Closed
adamw opened this issue Jun 12, 2021 · 1 comment · Fixed by #13083
Closed

Method type parameter not inferred when given a dependent type #12803

adamw opened this issue Jun 12, 2021 · 1 comment · Fixed by #13083
Assignees
Milestone

Comments

@adamw
Copy link
Contributor

adamw commented Jun 12, 2021

Compiler version

3.0.1-RC1

Minimized code

trait X {
  type Y
}

trait E[A]

trait Test {
  val x: X
  def wrap(x: X): E[x.Y] = ???
  def run[I](i: E[I]): Unit = ???
  run(wrap(x))
}

Output

[error] -- [E007] Type Mismatch Error: /Users/adamw/projects/tapir/client/tests/src/main/scala/sttp/tapir/client/tests/ClientStreamingTests.scala:35:10
[error] 35 |  run(wrap(x))
[error]    |      ^^^^^^^
[error]    |      Found:    sttp.tapir.client.tests.E[Test.this.x.Y]
[error]    |      Required: sttp.tapir.client.tests.E[?1.Y]
[error]    |
[error]    |      where:    ?1 is an unknown value of type sttp.tapir.client.tests.X
[error] Explanation
[error] ===========
[error]
[error] I tried to show that
[error]   sttp.tapir.client.tests.E[Test.this.x.Y]
[error] conforms to
[error]   sttp.tapir.client.tests.E[?1.Y]
[error] but the comparison trace ended with `false`:
[error]
[error]   ==> sttp.tapir.client.tests.E[Test.this.x.Y]  <:  sttp.tapir.client.tests.E[?1.Y]
[error]     ==> sttp.tapir.client.tests.E[Test.this.x.Y]  <:  sttp.tapir.client.tests.E[?1.Y] (recurring)
[error]       ==> ?1.Y  <:  Test.this.x.Y
[error]         ==> ?1.Y  <:  Test.this.x.Y (recurring)
[error]           ==> ?1.Y  <:  Test.this.x.Y (recurring)
[error]             ==> (?1 : sttp.tapir.client.tests.X)  <:  (Test.this.x : sttp.tapir.client.tests.X)
[error]               ==> (?1 : sttp.tapir.client.tests.X)  <:  (Test.this.x : sttp.tapir.client.tests.X) (recurring)
[error]                 ==> sttp.tapir.client.tests.X  <:  (Test.this.x : sttp.tapir.client.tests.X) (left is approximated)
[error]                   ==> sttp.tapir.client.tests.X  <:  (Test.this.x : sttp.tapir.client.tests.X) (recurring)
[error]                   <== sttp.tapir.client.tests.X  <:  (Test.this.x : sttp.tapir.client.tests.X) (recurring) = false
[error]                 <== sttp.tapir.client.tests.X  <:  (Test.this.x : sttp.tapir.client.tests.X) (left is approximated) = false
[error]               <== (?1 : sttp.tapir.client.tests.X)  <:  (Test.this.x : sttp.tapir.client.tests.X) (recurring) = false
[error]             <== (?1 : sttp.tapir.client.tests.X)  <:  (Test.this.x : sttp.tapir.client.tests.X) = false
[error]             ==> Any  <:  Test.this.x.Y (left is approximated)
[error]               ==> Any  <:  Test.this.x.Y (recurring)
[error]               <== Any  <:  Test.this.x.Y (recurring) = false
[error]             <== Any  <:  Test.this.x.Y (left is approximated) = false
[error]           <== ?1.Y  <:  Test.this.x.Y (recurring) = false
[error]         <== ?1.Y  <:  Test.this.x.Y (recurring) = false
[error]       <== ?1.Y  <:  Test.this.x.Y = false
[error]     <== sttp.tapir.client.tests.E[Test.this.x.Y]  <:  sttp.tapir.client.tests.E[?1.Y] (recurring) = false
[error]   <== sttp.tapir.client.tests.E[Test.this.x.Y]  <:  sttp.tapir.client.tests.E[?1.Y] = false
[error]
[error] The tests were made under a constraint with:
[error]  uninstantiated variables:
[error]  constrained types: [I](i: sttp.tapir.client.tests.E[I]): Unit
[error]  bounds:
[error]      I := ?1.Y
[error]  ordering:
[error] one error found

Expectation

Compile without errors :)

The above compiles fine using 2.13.

With Scala 3, the type parameter needs to be provided explicitly:

run[x.Y](wrap(x))
@romanowski
Copy link
Contributor

Assigning wrap(x) to val / def also make this snippet compile.

odersky added a commit to dotty-staging/dotty that referenced this issue Jul 15, 2021
We were too fast skolemizing the argument type as lower bound for a dependent parameter.
We need to do that only if the argument is unstable.

Fixing this revealed another problem in i6882a.scala, where we now got
confused by instantiating a poly type to a polymorphic function type
that contained the same polytype again. We avaoid that now by creating
a fresh copy of the polytype.

Fixes scala#12803
odersky added a commit to dotty-staging/dotty that referenced this issue Jul 24, 2021
We were too fast skolemizing the argument type as lower bound for a dependent parameter.
We need to do that only if the argument is unstable.

Fixing this revealed another problem in i6882a.scala, where we now got
confused by instantiating a poly type to a polymorphic function type
that contained the same polytype again. We avaoid that now by creating
a fresh copy of the polytype.

Fixes scala#12803
@Kordyjan Kordyjan added this to the 3.1.0 milestone Aug 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants