Skip to content

Unexpected type widening after copy #25735

@felix-hedenstrom

Description

@felix-hedenstrom

Compiler version

3.3.7, 3.7.4, 3.8.3

Minimized code

//> using scala 3.8.3

enum Animal:
  case Cat(meow: String)
  
def meow(cat: Animal.Cat): String = cat.meow
  
@main
def main: Unit =  {
  val cat: Animal.Cat = Animal.Cat("meow")

  val catWithBetterMeow = cat.copy(meow = "_€%")

  println(meow(catWithBetterMeow))
}

Output

[error] ./copy-issue.scala:14:16
[error] Found:    (catWithBetterMeow : Animal)
[error] Required: Animal.Cat
[error]   println(meow(catWithBetterMeow))
[error]                ^^^^^^^^^^^^^^^^^

Expectation

For the type of catWithBetterMeow to be inferred as Animal.Cat and that the program compiled.

We can explicitly annotate it with val catWithBetterMeow: Animal.Cat in which case it compiles fine.

Metadata

Metadata

Assignees

No one assigned

    Labels

    itype:bugstat:needs triageEvery issue needs to have an "area" and "itype" label

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions