Skip to content
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

Type system breach in multiple assignment #5106

Closed
scabug opened this issue Oct 22, 2011 · 3 comments
Closed

Type system breach in multiple assignment #5106

scabug opened this issue Oct 22, 2011 · 3 comments
Assignees
Labels
Milestone

Comments

@scabug
Copy link

scabug commented Oct 22, 2011

I think this deserves more than an "unchecked" warning:

scala> def f {
     | val (n, l): (String, Int) = (4, "");
     | }
warning: there were 2 unchecked warnings; re-run with -unchecked for details
f: Unit

scala> f
java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.String
[...]

This is specially surprising because this other very similar case (created from #140, which I initially thought was the same bug) works as I expected:

scala> def g {
     | val (n: String, l: Int) = (4, "");
     | }
<console>:8: error: scrutinee is incompatible with pattern type;
 found   : String
 required: Int
       val (n: String, l: Int) = (4, "");
               ^
<console>:8: error: type mismatch;
 found   : String
 required: Int
       val (n: String, l: Int) = (4, "");
             ^
<console>:8: error: scrutinee is incompatible with pattern type;
 found   : Int
 required: String
       val (n: String, l: Int) = (4, "");
                          ^
<console>:8: error: type mismatch;
 found   : Int
 required: String
       val (n: String, l: Int) = (4, "");
@scabug
Copy link
Author

scabug commented Oct 22, 2011

Imported From: https://issues.scala-lang.org/browse/SI-5106?orig=1
Reporter: @jsalvata
Affected Versions: 2.9.0-1, 2.9.2
Other Milestones: 2.10.0

@scabug
Copy link
Author

scabug commented Oct 22, 2011

@jsalvata said:
This is different from SUGGEST-4 -- those throw MatchErrors, not ClassCastExceptions. And none of the examples there is so blatant.

@scabug
Copy link
Author

scabug commented May 3, 2012

@adriaanm said:
seems fixed in master:

scala> val (n, l): (String, Int) = (4, "")
<console>:7: error: type mismatch;
 found   : Int(4)
 required: String
       val (n, l): (String, Int) = (4, "")
                                    ^
<console>:7: error: type mismatch;
 found   : String("")
 required: Int
       val (n, l): (String, Int) = (4, "")
                                       ^

scala>  val (n: String, l: Int) = (4, "");
<console>:7: error: scrutinee is incompatible with pattern type;
 found   : String
 required: Int
        val (n: String, l: Int) = (4, "");
                ^
<console>:7: error: scrutinee is incompatible with pattern type;
 found   : Int
 required: String
        val (n: String, l: Int) = (4, "");

@scabug scabug closed this as completed May 3, 2012
@scabug scabug added the patmat label Apr 7, 2017
@scabug scabug added this to the 2.10.0-M3 milestone Apr 7, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants