scala3 icon indicating copy to clipboard operation
scala3 copied to clipboard

Dependent type isn't inferred correctly in the body

Open peter-jerry-ye opened this issue 3 years ago • 0 comments

Compiler version

3.2.0

Minimized code

type LeafElem[X] = X match
  case String => Char
  case Array[t] => LeafElem[t]
  case Iterable[t] => LeafElem[t]
  case AnyVal => X

def leafElem[X](x: X): LeafElem[X] = x match
  case x: String      => x.charAt(0)
  case x: Array[t]    => leafElem(x(0))
  case x: Iterable[t] => leafElem(x.head)
  case x: AnyVal      => {
    val p: LeafElem[X] = x
    p
  }

Output

the p is not inferred correctly

image

Expectation

p, which has the same type signature as the return type, gets inferred correctly.

peter-jerry-ye avatar Sep 12 '22 05:09 peter-jerry-ye