Closed Bug 1683727 Opened 4 years ago Closed 4 years ago

Improve error messages when private fields are not found

Categories

(Core :: JavaScript Engine, task, P1)

task

Tracking

()

RESOLVED FIXED
87 Branch
Tracking Status
firefox87 --- fixed

People

(Reporter: jorendorff, Assigned: jorendorff)

References

Details

Attachments

(1 file)

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.

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.

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.

Assignee: nobody → jorendorff
Status: NEW → ASSIGNED
Status: ASSIGNED → NEW
Priority: -- → P1
Status: NEW → ASSIGNED

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.

Flags: needinfo?(jorendorff)
Pushed by jorendorff@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/dd2cf6eff8e8 Improve error messages when private fields are not found. r=mgaudet
Status: ASSIGNED → RESOLVED
Closed: 4 years ago
Resolution: --- → FIXED
Target Milestone: --- → 87 Branch
Flags: needinfo?(jorendorff)
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: