Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Feature Request: Improve misleading error message value ... is not a member of ... #23838

GLI-RK0 started this conversation in Feature Requests
Discussion options

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.

You must be logged in to vote

Replies: 1 comment

Comment options

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.

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
better-errors Issues concerned with improving confusing/unhelpful diagnostic messages

AltStyle によって変換されたページ (->オリジナル) /