Skip to content

Type mismatch for union types is slow #2030

Closed
@olafurpg

Description

@olafurpg

To reproduce, running from commit db24246

$ cat target/union.scala
object a {
   val x: String | Int = 'a
}
$ time ./bin/dotc target/union.scala
-- [E007] Type Mismatch Error: target/union.scala ------------------------------
2 |   val x: String | Int = 'a
  |                         ^^
  |                         found:    Symbol
  |                         required: String | Int
  |

one error found
./bin/dotc target/union.scala  30.37s user 1.44s system 262% cpu 12.094 total

I ran jprofiler on a repl session to see what was happening and got these results
union-typeerror.zip
I don't know much about Dotty's typer to make sense of the report.

My understanding from @DarkDimius's comment on Gitter is that union types put a strain on the type-checker for several fundamental reasons. However, 12s to report a type-error on a minimal example sounds like a bug to me.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions