Type inference bug for type member based on a dependent type
See original GitHub issueCompiler version
3.0.0
Minimized code
trait X:
type Out
def value: Out
class XWrapper[XX <: X](val x: XX):
type Out = x.Out
object XWrapper:
type Aux[T, U] = XWrapper[T] { type Out = U }
def getValue[XX <: X, U](y: XWrapper.Aux[XX, U]): U =
y.x.value
Output
Compilation error:
Found: y.x.Out
Required: U
y.x.value
Expectation
The compiler should know that y.x.Out and U are the same type
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Failed type inference when path dependent types are used as ...
I don't know if this is the right place to report it, but this code demonstrates an issue when path dependent types are...
Read more >How to help the Scala 3 compiler infer a path-dependent-type?
To make this compile we could use singleton types class B(val a: a0.type) or add a type parameter class B[_T](val a: A {...
Read more >Type inference for object definitions - open-std
This feature allows declarations to infer types from the expressions that are used as their initializers. This is part of a series of...
Read more >Type Inference, Haskell and Dependent Types - Adam Gundry
The first part proposes an approach to unification and type inference, based on information increase in dependency-ordered contexts, and keeping careful ...
Read more >What is the runtime/time complexity of Coq's (Dependent ...
I was wondering, since Coq allows programs/values themselves to be in the Type somehow my guess would be that type inference is either:...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Both
X
andXWrapper
have a member calledOut
, but they’re not the same member. Let’s give them their own name to make things clearer:Here I think it’s clear that the issue is that
A
does not matchU
, the value ofB
doesn’t matter sincey.x
has typey.x.A
.When the compiler checks
y.x.A <: U
,U
isn’t constrained (it’s declared as justU
without bounds indef getValue[XX <: X, U]
), the fact thatU
has to be equal toy.x.A
is something that can be derived from the fact that it appears as the rhs ofB
and thatB
is already defined to be equal tox.A
, but that’s a very indirect complex reasoning the compiler isn’t going to perform.