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

Error on type computation #9228

Closed
flomebul opened this issue Jun 23, 2020 · 4 comments · Fixed by #11012
Closed

Error on type computation #9228

flomebul opened this issue Jun 23, 2020 · 4 comments · Fixed by #11012

Comments

@flomebul
Copy link
Contributor

Moving from Dotty 0.24-RC1 to Dotty 0.25-RC2, if found an issue.

Minimized code

object ABug {

  class Graph { class Node }

  def ltol[O](tb: List[O]): List[O] = ???

  def gtoll(using g: Graph): List[List[g.Node]] = ???

  object graph extends Graph
  import graph._
  given graph.type = graph

  val osq: List[List[Node]] = gtoll

  val r: List[List[Any ]] = ltol(gtoll)
  val q: List[List[Node]] = ltol(gtoll)

}

Output

-- [E007] Type Mismatch Error: ABug.scala:16:32 --------------------------------
16 |  val q: List[List[Node]] = ltol(gtoll)
   |                            ^^^^^^^^^^^
   |                            Found:    List[List[Any]]
   |                            Required: List[List[ABug.graph.Node]]
1 error found

Expectation

A do not have such an error in dotty 0.24

@odersky
Copy link
Contributor

odersky commented Jun 25, 2020

This was caused by

#8824

@odersky
Copy link
Contributor

odersky commented Jun 25, 2020

The comment of #8824 says:

Use wildcards for result type approximation of dependent implicit methods.
In a situation like

 def f(using x: T): C[x.Out]

we need to go constrain the result type of f before doing the implicit
search for T. Previously we created a fresh type variable param(1) with
T & Singleton as upper bound. That works well for other uses of
result type approximation, but in this case, we miss constraining
param(1) from below by the result of the implicit search. So in the end
param(1) gets interpolated to its upper bound, which leads to problems.

One possible solution is to add the missing lower constraint for the dependent
type variable. But it's easier to just use a Wildcard type, which is what
this PR does.

I tried to fix it by adding the missing lower constraint for the dependent
type variable but this causes pickling failures. The problem is that we are simply
not prepared at the moment to have dependent term parameters that get
substituted in constraints. This would demand a major change, with unknown
costs of effort and compile-time performance. Maybe there will be enough motivation
to tackle this in the context of adding general dependent types to Scala. But
for the moment I don't see #9228 can be fixed in isolation.

Reverting #8824 is not an option either since this one fixed several type inference problems
where scalac compiled OK but dotty did not. So for the moment we need to accept this
as a limitation of type inference.

@flomebul
Copy link
Contributor Author

My understating is that, in such case, the work around is to comment the "using" and use explicit parameter, right ?

odersky added a commit to dotty-staging/dotty that referenced this issue Jan 6, 2021
@odersky
Copy link
Contributor

odersky commented Jan 6, 2021

I suspect this was fixed with the recent changes to wildcard instantiation #10924.

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.

3 participants