Skip to content

betterFors trailing map elimination can change the resulting type #21804

@KacperFKorban

Description

@KacperFKorban

Compiler version

3.6.1-RC1-bin-20241017-59b67fc-NIGHTLY

Minimized code

//> using scala 3.nightly import scala.language.experimental.betterFors case class Container[A](val value: A) { def map[B](f: A => B): Container[B] = Container(f(value)) } sealed trait Animal case class Dog() extends Animal def opOnDog(dog: Container[Dog]): Container[Animal] = for v <- dog yield v

Output

-- [E007] Type Mismatch Error: /home/kpi/bugs/better-fors-bug.scala:13:2 ------- 13 | for | ^ | Found: (dog : Container[Dog]) | Required: Container[Animal] 14 | v <- dog 15 | yield v | | longer explanation available when compiling with `-explain`

without betterFors enabled, this code compiles successfully.

Expectation

The type of the for-comprehension should not be changed after enabling the betterFors language extension.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions