Skip to content

val 1 = 0 in the REPL should MatchError (SI-4939 redux) #10214

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
SethTisue opened this issue Nov 6, 2020 · 3 comments · Fixed by #10723
Closed

val 1 = 0 in the REPL should MatchError (SI-4939 redux) #10214

SethTisue opened this issue Nov 6, 2020 · 3 comments · Fixed by #10723

Comments

@SethTisue
Copy link
Member

Scala 2 behavior is correct, as per scala/bug#4939

scala 2.13.3> val 1 = 0
scala.MatchError: 0 (of class java.lang.Integer)

but in Scala 3.0.0-M1:

scala> val 1 = 0

scala>                                                                                                                  

gitter today:

Michael Pilquist @mpilquist 12:21
out of curiosity, why does val 1 = 0 not throw a match error or otherwise fail in dotty repl?

Guillaume Martres @smarter 12:22
that's definitely a bug
the exception must be caught and ignored somewhere

@mpilquist
Copy link
Contributor

Note the test case from the linked issue fails too:

scala> object O { val 1 = 2; def x = 1 }
// defined object O

scala> O.x
scala.MatchError: 2 (of class java.lang.Integer)
	at rs$line$1$O$.<clinit>(rs$line$1:1)
	at rs$line$2$.<clinit>(rs$line$2:1)
	at rs$line$2.res0(rs$line$2)

@smarter smarter changed the title val 1 = 0 should MatchError (SI-4939 redux) val 1 = 0 in the REPL should MatchError (SI-4939 redux) Nov 6, 2020
@SethTisue
Copy link
Member Author

@mpilquist I think that test case (which was mine, almost a decade ago) was misconceived. That behavior is actually correct; the def x is a red herring. It boils down to:

scala 2.13.3> object O { val 1 = 2 }
object O

scala 2.13.3> O
scala.MatchError: 2 (of class java.lang.Integer)

which Dotty already handles correctly.

so I think this isn't actually scala/bug#4939 returning; it's merely the REPL-only scala/bug#4950 returning.

@som-snytt
Copy link
Contributor

The old Scala 2 REPL had two objects, one to wrap user code and a second to pull values out and compose a string to display. The second object was endowed with a reference to the first, to ensure initialization in the absence of members. This is currently done reflectively. I mean currently in Scala 3.

@Kordyjan Kordyjan added this to the 3.0.0 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.

6 participants