Improve message for var/const pass
Closing #1229 .
-
has a changelog entry
Merge request reports
Activity
- Resolved by Christian Rinderknecht
I would recommend simply the following message: "A constant value cannot be reassigned.\nHint: Declare it instead as "var" or remove the assignment."
added 1 commit
- 707e3bec - Apply Christian's suggestion + in vars mark error location in usage not in decl.
Sorry, but, to me "A constant value cannot be reassigned" sounds either tautologous or nonsensical. I'm not sure it will make sense to users...
"declare it instead as variable or remove the assignment." is getting more to the point, but still seems rather cryptic...
Why not something more like:
Assignment to variable xyz is forbidden because it was declared "const xyz" at LOCATION. Declare it as "var xyz" instead to allow assignment.
This still doesn't seem great but I think users will understand it.
Is the problem though that the error doesn't know the user is using Pascaligo? Can this error also occur in JsLigo?
Edited by Tom JackCf firefox JS:
> const x = 1 > x = 2 Uncaught TypeError: invalid assignment to const 'x' ...location info...
It does say "const" and "x" at least. It doesn't seem to give the declaration location. It doesn't recommend "var" or "let".
For JS one can of course search for the error message... https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/Invalid_const_assignment
Edited by Tom Jack- Resolved by Christian Rinderknecht
I am always fine with longer messages. About the tautology: it's not, it actually means "A constant variable". I prefer an apparent tautology to an apparent contradiction. The location of the declaration may be unwieldy. The JS message could leave open that there exists another way to assign.
mentioned in commit ec97fdf1
unassigned @er433