Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Duplicate
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: Misc Compiler
    • Labels:

      Description

      That's a nice vague summary! It's OK though because I'm assigning it to myself. My motivation of the moment is as described in an email quoted below, but I have others in mind, and hopefully people can remind me of their least favorites in the comments.

      I have a method that takes a List[A] as a parameter, where A was unbounded,
      and was matching on the list and calling .getClass on its head.  It's pretty
      clear in retrospect that this won't work, since A is effectively Any, and
      .getClass is only applicable to AnyRef, but the resulting error message
      could use some work:
          
      >                                                                               
      /home/acruise/dev/subserveo/svn/SkyHook-trunk/util/src/main/scala/com/subserve  
      o/util/ScalaUtils.scala:7:                                                      
      > error: type mismatch;                                                         
      >  found   : A                                                                  
      >  required: ?{val getClass: ?}                                                 
      > Note that implicit conversions are not applicable because they are            
      > ambiguous:                                                                    
      >  both method any2stringadd in object Predef of type (x:                       
      > Any)scala.runtime.StringAdd                                                   
      >  and method any2ArrowAssoc in object Predef of type [A](x: A)ArrowAssoc[A]    
      >  are possible conversion functions from A to ?{val getClass: ?}               
      >         case x :: xs if manifestB.erasure.isAssignableFrom(x.getClass) =>     
          
      

        Issue Links

          Activity

          Hide
          Jason Zaugg added a comment -
          scala> case class C(a: Any)
          defined class C
          
          scala> (new C(())) match {
               |    case C =>
               | }
          <console>:9: error: pattern type is incompatible with expected type;
           found   : object C
           required: C
                    case C =>
                         ^
          

          Suggested type diagnostics:

          "Note: you referred to the companion object of the class C. Perhaps you meant '_ : C' or 'C(_)'

          Show
          Jason Zaugg added a comment - scala> case class C(a: Any) defined class C scala> (new C(())) match { | case C => | } <console>:9: error: pattern type is incompatible with expected type; found : object C required: C case C => ^ Suggested type diagnostics: "Note: you referred to the companion object of the class C. Perhaps you meant '_ : C' or 'C(_)'
          Hide
          hanna added a comment -

          I do understand why this and similar code won't compile (two nodes vs. one), but the compiler message is a bit cryptic, I think.

           
          scala> val test = true match { case true => <br/><br/> case false => <br/> }
          
          <console>:7: error: kinds of the type arguments (Seq[Any]) do not conform to the expected
          kinds of the type parameters (type CC) in class GenericCompanion.
          Seq[Any]'s type parameters do not match type CC's expected parameters: trait Seq has one
          type parameter, but type CC has one
                 val test = true match { case true => <br/><br/> case false => <br/> }
                     ^
          
          Show
          hanna added a comment - I do understand why this and similar code won't compile (two nodes vs. one), but the compiler message is a bit cryptic, I think. scala> val test = true match { case true => <br/><br/> case false => <br/> } <console>:7: error: kinds of the type arguments (Seq[Any]) do not conform to the expected kinds of the type parameters (type CC) in class GenericCompanion. Seq[Any]'s type parameters do not match type CC's expected parameters: trait Seq has one type parameter, but type CC has one val test = true match { case true => <br/><br/> case false => <br/> } ^
          Hide
          Paul Phillips added a comment -

          Ha, I did one better on that last one and just made it work.

          scala> val test = true match { case true => <br/><br/> case false => <br/> }
          test: Seq[scala.xml.Node] with Serializable = ArrayBuffer(<br></br>, <br></br>)
          
          Show
          Paul Phillips added a comment - Ha, I did one better on that last one and just made it work. scala> val test = true match { case true => <br/><br/> case false => <br/> } test: Seq[scala.xml.Node] with Serializable = ArrayBuffer(<br></br>, <br></br>)
          Hide
          Alex Cruise added a comment -

          Also note that Any#getClass actually works now

          Show
          Alex Cruise added a comment - Also note that Any#getClass actually works now
          Hide
          Simon Ochsenreither added a comment -

          I have checked the comments and created a new ticket for each appropriate one. I'll close this as all complaints mentioned here are either fixed, or tracked as individual tickets (SI-4878, SI-4879).

          The new metabug tracking most of compiler error message-related issues is SI-4876.

          Show
          Simon Ochsenreither added a comment - I have checked the comments and created a new ticket for each appropriate one. I'll close this as all complaints mentioned here are either fixed, or tracked as individual tickets ( SI-4878 , SI-4879 ). The new metabug tracking most of compiler error message-related issues is SI-4876 .

            People

            • Assignee:
              Paul Phillips
              Reporter:
              Paul Phillips
              TracCC:
              Alex Cruise, Erik Engbrecht, Indrajit Raychaudhuri, Ismael Juma, Johannes Rudolph, Mark Harrah, nikolaj lindberg, Paul Phillips, Pavol Vaskovic, Seth Tisue
            • Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development