Skip to content

Type mismatch for union types is slow #2030

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
olafurpg opened this issue Feb 24, 2017 · 3 comments
Closed

Type mismatch for union types is slow #2030

olafurpg opened this issue Feb 24, 2017 · 3 comments

Comments

@olafurpg
Copy link
Contributor

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.

@DarkDimius
Copy link
Contributor

However, 12s to report a type-error on a minimal example sounds like a bug to me.

12s is indeed unreasonable.

@odersky
Copy link
Contributor

odersky commented Feb 25, 2017

It's a diverging implicit search involving Any2ArrowAssoc and Ensuring and other fundamental Predef decorators. They should not try to form nested implicit conversions but for some reason they do. I have to find out why.

@odersky odersky closed this as completed in 761b1fd Mar 3, 2017
@olafurpg
Copy link
Contributor Author

olafurpg commented Mar 3, 2017

Thank you! I can confirm that the type error is now reported instantaneously for the example above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants