Skip to content

Compiler hangs on invalid type cast in for comprehension #12220

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
rom9 opened this issue Apr 26, 2021 · 0 comments · Fixed by #12223
Closed

Compiler hangs on invalid type cast in for comprehension #12220

rom9 opened this issue Apr 26, 2021 · 0 comments · Fixed by #12223
Milestone

Comments

@rom9
Copy link

rom9 commented Apr 26, 2021

Compiler version

scala3-3.0.0-RC3

$ java -version
openjdk version "1.8.0_272"
OpenJDK Runtime Environment (build 1.8.0_272-b10)
OpenJDK 64-Bit Server VM (build 25.272-b10, mixed mode)

Minimized code

$ bin/scala
scala> val a: List[Any] = List(List(1,2), List(3,4))
val a: List[Any] = List(List(1, 2), List(3, 4))

scala> for(b <- a ; c <- b.asInstanceOf[List]) { println(c) }
^C

Output

the above code hangs forever with no output, and with zero CPU usage.

If i do the same cast in a separate val, i get the expected compilation error:

scala> for(b <- a) { val c = b.asInstanceOf[List] ; for(d <- c) { println(d) } }
1 |for(b <- a) { val c = b.asInstanceOf[List] ; for(d <- c) { println(d) } }
  |                   ^
  |                   Missing type parameter for List

scala>

Expectation

Compilation fails with "Missing parameter type ..." error

@rom9 rom9 added the itype:bug label Apr 26, 2021
odersky added a commit to dotty-staging/dotty that referenced this issue Apr 26, 2021
The previous code was a great demonstration of the perils of mixing mutable variables with
delayed evaluation.

Also, make lazy vals in Message @ThreadUnsafe. This means that any recursion (like the one we
encountered before the fix) manifests itself in stackoverflows instead of deadlocks.

Fixes scala#12220
@Kordyjan Kordyjan added this to the 3.0.1 milestone Aug 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants