Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve faulty compilation - semantic error #12919

Conversation

privat
Copy link
Contributor

@privat privat commented Mar 7, 2023

This PR extends AST API with basic methods for semantic error

  • addError: to let compiler add semantic error information on Node
  • isError to let AST user knows if the node is erroneous
  • isFaulty is extended to encompass both syntax error (RBParseErrorNode) and other kind of errors (isError)

The internal implementation is to use a node property #error.

Currently, (I'm not aware of a plan to add more semantic error, so this is not the better term) there seems to be only 2 semantic errors: unwritable variable (for some reason read-only and reserved are distinguished) and too much argument (for block and methods), the latter was moved from backend to the semantic analysis (because the whole point of semantic analysis is to get these errors before compilation).
The status of undeclared variable as error is unclear and seems to depend on UI related stuff (and possibly the humidity level).

The code is deliberately written as simple as possible, first attempts were too much complex for a limited gain.

A possible future improvement could be to unify and reify errors and warnings (strings are poor).
Maybe look at how critiques does the deal.

UI related concerns (like nice icons in the icon bar) will be added in a future PR.

Another question is how much people like (or rely) on the current semantic error/warnings exception hierarchy (OCSemanticError, OCStoreIntoReadOnlyVariableError, OCStoreIntoReservedVariableError, OCSemanticWarning, OCShadowVariableWarning, OCUndeclaredVariableWarning)

@MarcusDenker
Copy link
Member

Broken build, not related to this change:

@MarcusDenker MarcusDenker reopened this Mar 7, 2023
Copy link
Contributor

@demarey demarey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think #isFaulty and #isError should go in #testing protocol and not #errors.
It is the standard in the Pharo image.

@MarcusDenker MarcusDenker merged commit 54ad3b3 into pharo-project:Pharo11 Mar 8, 2023
@demarey
Copy link
Contributor

demarey commented Mar 8, 2023

So, are comments useful if merged without answer ???

@privat
Copy link
Contributor Author

privat commented Mar 8, 2023

@demarey where is the standard/style guide about protocols/categories on Pharo? I did not find one.

Personally, I prefer when methods are grouped by concerns, but if there are some rules I can follow them.

@demarey
Copy link
Contributor

demarey commented Mar 9, 2023

@privat You have some rules encoded in the Method classifier. Foe example, you can see methods starting with is are classified in the testing protocol. https://github.com/pharo-project/pharo/blob/Pharo11/src/Tool-Base/MethodClassifier.class.st#L84
At the end, it is up to you to choose the protocols.

GitHub
Pharo is a dynamic reflective pure object-oriented language supporting live programming inspired by Smalltalk. - pharo/MethodClassifier.class.st at Pharo11 · pharo-project/pharo

@privat
Copy link
Contributor Author

privat commented Mar 9, 2023

@demarey thank you for the pointer. Although a list of heuristics on substrings to determinate some default protocol is not what I envisioned for "rule" or a "standard" :)
They are fine as they seem able to guess something that works (and far more usable than "as yes unclassified"), but I do not think programmers should follow them blindly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants