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

too many error messages are too opaque #3092

Closed
scabug opened this issue Feb 22, 2010 · 16 comments
Closed

too many error messages are too opaque #3092

scabug opened this issue Feb 22, 2010 · 16 comments

Comments

@scabug
Copy link

scabug commented Feb 22, 2010

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) =>     
    
@scabug
Copy link
Author

scabug commented Feb 22, 2010

Imported From: https://issues.scala-lang.org/browse/SI-3092?orig=1
Reporter: @paulp
Duplicates #4876

@scabug
Copy link
Author

scabug commented Feb 27, 2010

@paulp said:
In r21008 I put in an error message which borders on great literature. Still awaiting comments on other errors which could be improved, hint hint.

@scabug
Copy link
Author

scabug commented Mar 8, 2010

@harrah said:
I would not label this as my least favorite, but since it came up, but I will at least record it here.

Compiling this code:

object T {
  var X = 3
  val y =
    5 match {
      case X => true
      case _ => false
    }
}

gives the error message:

A.scala:5: not found: value X
      case X => true
           ^

An improvement might be "X is not a stable identifier" or similar.

@scabug
Copy link
Author

scabug commented Mar 24, 2010

@paulp said:
Reminder to self, heard on IRC:

I'm trying to use the keySet method on a Map but get this error: not enough arguments for method apply: (elem: com.google.appengine.api.datastore.Key)Boolean in trait SetLike. Unspecified value parameter elem.

@scabug
Copy link
Author

scabug commented Apr 17, 2010

Pavol Vaskovic (pali-at-pali.sk) said:

class Test {
  def foo {
    private def bar {}
  }
}

produces [[BR]]
error: illegal start of statement[[BR]]
private def bar {}

I'm unsure what would be better message, but the point is that the private modifier in this context is useless, because I'm already nested in a block. I find the current message puzzling, as I don't see a statement here.

@scabug
Copy link
Author

scabug commented Apr 27, 2010

@paulp said:
Note to self: see if you can warn people who say

CollectionType[_] <: java.util.Collection[_]

when what they mean is

CollectionType[X] <: java.util.Collection[X] 

@scabug
Copy link
Author

scabug commented Apr 30, 2010

@paulp said:
Note to self: people are constantly expressing confusion at error messages like this:

found  : Int
required: String

...understandably enough, because they just happen to be doing something with '+' and the compiler unhelpfully interprets their efforts as something involving any2stringadd. Boy I'd sure like to turn that light off someday.

@scabug
Copy link
Author

scabug commented May 23, 2010

@paulp said:
Note to self: Zaugg says, with respect to type inference on partial function literals:

Let's just agree that you'd be considered a light-year more awesome if
you could train the compiler to say "Please see �8.5 of the Scala
Reference" rather than the blather about x0$$1 and expanded functions.

Clearly this suggestion has priority since it comes with a quantified awesomeness increase.

@scabug
Copy link
Author

scabug commented Aug 30, 2010

nikolaj lindberg (nikolaj) said:
Don't know if this qualifies as opaque enough, and I also don't know if there is something you can do about it. Anyway, sometimes I forget the "def" when writing an auxiliary constructor:

// Eg.scala
class Eg(name: String) {
 this() = this("DEFAULT")
}

$$ scalac Eg.scala 
Eg.scala:2: error: value update is not a member of Eg
 this() = this("DEFAULT")
 ^
one error found

(I now immediately recognise the problem and simply add the missing "def", but the first few times, I found the error message a tiny bit cryptic.)

@scabug
Copy link
Author

scabug commented Oct 7, 2010

@paulp said:
(In r23210) Positioning fix closes #3092, no review.

@scabug
Copy link
Author

scabug commented Oct 7, 2010

@harrah said:
meant #3902

@scabug
Copy link
Author

scabug commented Dec 23, 2010

@retronym said:

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(_)'

@scabug
Copy link
Author

scabug commented May 26, 2011

hanna said:
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/> }
           ^

@scabug
Copy link
Author

scabug commented Jul 27, 2011

@paulp said:
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>)

@scabug
Copy link
Author

scabug commented Jul 27, 2011

@acruise said:
Also note that Any#getClass actually works now :)

@scabug
Copy link
Author

scabug commented Aug 6, 2011

@soc said:
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 (#4878, #4879).

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants