Skip to content

Dependent type isn't inferred correctly in the body #16021

Closed as not planned
Closed as not planned
@peter-jerry-ye

Description

@peter-jerry-ye

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions