Improve error messages when private fields are not found
Categories
(Core :: JavaScript Engine, task, P1)
Tracking
()
Tracking | Status | |
---|---|---|
firefox87 | --- | fixed |
People
(Reporter: jorendorff, Assigned: jorendorff)
References
Details
Attachments
(1 file)
(deleted),
text/x-phabricator-request
|
Details |
In some cases our error message is just wrong. For example:
class X {
#f = 0;
static m(obj) {
obj.#f = 1; // TypeError: Trying to read undeclared field
}
}
X.m({});
Of course we're trying to write it, not read it.
Assignee | ||
Comment 1•4 years ago
|
||
Node currently says Cannot write private member #f to an object whose class did not declare it
.
The most informative message would be like can't set private field '#f': 'obj' is not the right class (expected 'X', got 'Object')
However, adding useful data to this error message is nontrivial because it'll affect bytecode. Maybe for now I should just change it to can't set private field: object is not the right class
. And in the get
case, can't access private field or method: object is not the right class
.
Assignee | ||
Comment 2•4 years ago
|
||
Previously we always said "Trying to read" even when the error occurred while
trying to write.
The use of "object" in the new messages is inaccurate when the user is trying
to set a private field on a primitive value, but this is the best I can do
without adding fields to the error message--which would have to affect
bytecode.
Updated•4 years ago
|
Assignee | ||
Updated•4 years ago
|
Assignee | ||
Updated•4 years ago
|
Comment 3•4 years ago
|
||
There's a r+ patch which didn't land and no activity in this bug for 2 weeks.
:jorendorff, could you have a look please?
For more information, please visit auto_nag documentation.
Comment 5•4 years ago
|
||
bugherder |
Assignee | ||
Updated•4 years ago
|
Description
•