Invalid use of declared private field reports incorrect line number
Categories
(Core :: JavaScript Engine, defect, P3)
Tracking
()
Tracking | Status | |
---|---|---|
firefox102 | --- | fixed |
People
(Reporter: blmatthews, Assigned: mgaudet)
References
Details
Attachments
(2 files)
User Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:100.0) Gecko/20100101 Firefox/100.0
Steps to reproduce:
Save the attached file and open it in Firefox with Tool > Browser Tools > Web Developer Tools open and on the Console (or Debugger) tab. Then edit the file and uncomment line 15.
Actual results:
With the file as attached (line 15 commented out), the console reports, as expected:
Uncaught SyntaxError: reference to undeclared private field or method #undeclaredPrivateField private.html:16:8
However, with line 15 uncommented, the console reports:
Uncaught SyntaxError: reference to undeclared private field or method #declaredPrivateField private.html:7:3
A couple of problems. First, the field isn't undeclared (although I suppose it's undeclared in the scope it's being used in), and second, and more problematic, the line number is the line number it's declared on, not where it's being used.
Expected results:
With line 15 uncommented the error should reference line 16.
Note that although m isn't (explicitly) declared and doesn't have a value, that doesn't matter, anywhere you attempt to invalidly reference a declared private field the error reports the line as the line the field is declared on, not where it's being referenced as one would expect. Private methods have the same problem.
Reporter | ||
Comment 1•2 years ago
|
||
Oops, of course the error should reference line 15, not 16.
Comment 2•2 years ago
|
||
The Bugbug bot thinks this bug should belong to the 'Core::JavaScript Engine' component, and is moving the bug to that component. Please correct in case you think the bot is wrong.
Assignee | ||
Updated•2 years ago
|
Assignee | ||
Comment 3•2 years ago
|
||
I can also reproduce this in the shell:
class Mainclass {
#declaredPrivateField = 42; // Line 2
}
m.#declaredPrivateField = 23; // Line 5
m.#undeclaredPrivateField = 23; // Line 6
With line 5 commented out we get
/Users/mgaudet/tmp/t.js:6:2 SyntaxError: reference to undeclared private field or method #undeclaredPrivateField:
/Users/mgaudet/tmp/t.js:6:2 m.#undeclaredPrivateField = 23; // Line 6
/Users/mgaudet/tmp/t.js:6:2 ..^
With line 5 un-commented, we get:
/Users/mgaudet/tmp/t.js:2:4 SyntaxError: reference to undeclared private field or method #declaredPrivateField
My recollection was that we stored information in the used names tracker to handle these sorts of error message problems, but this is definitely a huge paper cut.
Assignee | ||
Comment 4•2 years ago
|
||
ni? myself to look at this when I've got some spare time.
Assignee | ||
Comment 5•2 years ago
|
||
A bit of investigation:
Both errors are issued from the same place, as we have found undeclared private names in the provided scope.
The reason we're getting the wrong debug info for this when the private name is declared elsewhere is that in the UsedNameTracker
, we only track the first use position. Which made sense at one point, but this bug shows pretty clearly that this can result in very confusing error messages.
I'll bet this can be rectified relatively easily: If the vector of uses is empty when adding a new one, we should reset the firstUsePosition...
Assignee | ||
Comment 6•2 years ago
|
||
Updated•2 years ago
|
Comment 8•2 years ago
|
||
bugherder |
Description
•