-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Feature Request: Improve misleading error message value ... is not a member of ...
#23838
-
You can call :=+
on a var Seq
var s: Seq[Int] = Seq() s :+= 1
If you accidentally supply the wrong type of argument, it errors as expected
var s: Seq[Int] = Seq() s :+= "h" // error
but gives you a misleading error message
value :+= is not a member of Seq[Int] - did you mean Seq[Int].:+? or perhaps Seq[Int].:++?
It makes users consider that they are forgetting how the operator is spelt, or if they forgot to make the value a var
and not val
, etc.
Value :+=
is in fact a member of Seq[Int]
, even if :+=(str: String)
is not. This error message should be replaced with one that makes this clear, that :+=
does exist (for Int
in this case) but that the wrong type of argument is being supplied.
At the very least, the error message could be replaced to specify String
being the cause of the failure, like
value :+=(String) is not a member of Seq[Int]
to make the argument type mismatch more obvious, Ideally the message would also suggest the correct type.
Beta Was this translation helpful? Give feedback.
All reactions
Replies: 1 comment
-
I don't remember if there is an existing ticket, but I've left "notes to self" to port Scala 2 diagnostic for assignment operators:
scala> s :+= "hello, world"
^
error: value :+= is not a member of Seq[Int]
did you mean :+ or :++?
Expression does not convert to assignment because:
type mismatch;
found : String("hello, world")
required: Int
expansion: s = s.:+("hello, world")
That addendum is not even as precise as requested here. It happens to look similar.
Beta Was this translation helpful? Give feedback.