Better error message when the ; is missing at the end of class definition #4
Labels
No labels
bug
duplicate
enhancement
help wanted
invalid
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
BeRo1985/poca#4
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
The following snippet
fails to parse with error:
A better error message would be helpful, pointing that
returnright after}is not correct.Right now the
}orreturnare)I tested what JS reports for this, but it seems that missing
;is actually allowed. That is,works OK in a browser (Firefox) console and https://runjs.app/play .
You're right that JavaScript accepts this code without a semicolon after the closing } of the object literal. That is because JavaScript has a feature called "Automatic Semicolon Insertion" (ASI), the parser automatically inserts semicolons where it thinks they should go, which is even in the JavaScript community considered a controversial feature.
POCA deliberately doesn't have this feature, okay, it has, but it's inactive by default and must be enabled explicitly per preprocessor pragma directive (yes, POCA has also a full C preprocessor implementation). The reason is that ASI, while convenient, has a history of causing really subtle and frustrating bugs, the kind where your code looks perfectly fine but behaves in unexpected ways because the parser inserted a semicolon somewhere you didn't expect. So I made the design decision early on to require explicit semicolons. It's in fact a bit more typing, but it avoids a whole category of hard-to-debug issues.
In your example, just add a semicolon after the closing } of the object literal, and it will work fine.
I wasn't really asking to insert the
;like in JS.My point of this bugreport is that
Precedence level overflow(and with a line number quite far from the error) is a confusing error message in this case. An error message that suggests it's a bad syntax, and points around the place where;should be, would be more helpful.