Skip to content

Type mismatch when inferring with union types? #6751

Closed
@dwijnand

Description

@dwijnand

minimized code

... Sorry, I don't have a minimised form. But the error is reproducible in #6744, and the error detail is:

[error] -- [E007] Type Mismatch Error: /d/dotty/compiler/src/dotty/tools/dotc/printing/Formatting.scala:215:46
[error] 215 |    val toExplain: List[(String, Recorded)] = seen.toList.flatMap {
[error]     |                                              ^
[error]     |Found:    List[(String, Object & dotty.tools.dotc.printing.Showable)]
[error]     |Required: List[(String, dotty.tools.dotc.printing.Formatting.Recorded)]
[error] 216 |      case (key, entry :: Nil) =>
[error] 217 |        if (needsExplanation(entry)) (key.str, entry) :: Nil else Nil
[error] 218 |      case (key, entries) =>
[error] 219 |        for (alt <- entries) yield {
[error] 220 |          val tickedString = seen.record(key.str, key.isType, alt)
[error] 221 |          (tickedString, alt)
[error] 222 |        }
[error] 223 |    }.sortBy(_._1)
[error] one error found

expectation

It shouldn't error, as proven by helping the inferencer out by assigning the result of the flatMap op to val res: List[(String, Recorded)] and then returning that.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions