Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: Scala 2.9.0-1, Scala 2.9.2
    • Fix Version/s: Scala 2.10.0-M3, Scala 2.10.0
    • Component/s: Pattern Matcher
    • Labels:
      None
    • Environment:

      Tested on both 22-oct trunk (2.10.0.r25875-b20111022181326)
      and 2.9.0.1 from Ubuntu Oneiric

      Both on Java HotSpot(TM) Server VM, Java 1.6.0_24

      Description

      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 SI-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, "");
      

        Activity

        Hide
        Jordi Salvat i Alabart added a comment -

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

        Show
        Jordi Salvat i Alabart added a comment - This is different from SUGGEST-4 – those throw MatchErrors, not ClassCastExceptions. And none of the examples there is so blatant.
        Hide
        Adriaan Moors added a comment -

        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, "");
        
        Show
        Adriaan Moors added a comment - 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, "");

          People

          • Assignee:
            Adriaan Moors
            Reporter:
            Jordi Salvat i Alabart
          • Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development