-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Dependent type isn't inferred correctly in the body #16021
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
Comments
After reviewing with Marco and Sherwin, I don't think this is actually an inference bug. Per our understanding, cc: @dwijnand |
Intersectionless Scala 2 disallows the pattern match on In Scala 3, the pattern match really means |
Would saying |
To illustrate why this isn't actually a bug: type LeafElem[X] = X match
case String => Char
case Int => Float
def leafElem[X](x: X, y: X): LeafElem[X] = x match
case x: String => x.charAt(0)
case x: Int => {
val p: LeafElem[Int] = y.asInstanceOf[Int].toFloat
p
}
//class cast exception: Class java.lang.String cannot be cast to Integer
leafElem(4, "hello") With the match type, we are providing proof of a refined type for a shadowed value |
I agree. But, @peter-jerry-ye, feel free to comment if we missed something. |
@markehammons Thanks for explaining, now I see that the problem is that X was never replaced in the pattern match expression. Seems that I've misunderstood how things work. Maybe I should just sit and wait for @mbovel to make scala better suited for dependent typed programs. |
Compiler version
3.2.0
Minimized code
Output
the
p
is not inferred correctlyExpectation
p
, which has the same type signature as the return type, gets inferred correctly.The text was updated successfully, but these errors were encountered: