Skip to content

Improve Syntax Errors#166

Open
rcosta358 wants to merge 6 commits intomainfrom
improve-syntax-errors
Open

Improve Syntax Errors#166
rcosta358 wants to merge 6 commits intomainfrom
improve-syntax-errors

Conversation

@rcosta358
Copy link
Collaborator

@rcosta358 rcosta358 commented Feb 28, 2026

This PR improves the syntax error messages of refinements, ghosts, and aliases, and includes example usages of those.

Examples

image image image

In the future we'll include these examples as hints rather than in the error message itself.

@rcosta358 rcosta358 self-assigned this Feb 28, 2026
@rcosta358 rcosta358 added the error messages Related to error messages label Feb 28, 2026
@rcosta358 rcosta358 linked an issue Feb 28, 2026 that may be closed by this pull request
Optional<String> s = getErrors(toParse);
if (s.isPresent())
throw new SyntaxError(s.get(), toParse);
throw new SyntaxError("Invalid refinement expression, e.g. \"v > 0\"", toParse);
Copy link
Collaborator

Choose a reason for hiding this comment

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

The example in the PR confused me, I was thinking "why would i need to write v instead of x"? We have to be careful, so it isn't more confusing than helpful.
Maybe we could just have "it should be a logical predicate"

AliasDTO alias = av.getAlias(rc);
if (alias == null)
throw new SyntaxError("Alias definitions should be in format <name>(<parameters>) { <definition> }", s);
throw new SyntaxError("Invalid alias definition, e.g. \"Positive(int v) { v >= 0 }\"", s);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Lets include the whole alias reference like @RefinementAlias("...")

GhostDTO g = GhostVisitor.getGhostDecl(rc);
if (g == null)
throw new SyntaxError("Ghost declarations should be in format <type> <name> (<parameters>)", s);
throw new SyntaxError("Invalid ghost declaration, e.g. \"int size\"", s);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Lets include the whole alias reference like @Ghost("int size") to ensure that it is perceptible

@rcosta358 rcosta358 requested a review from CatarinaGamboa March 1, 2026 11:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

error messages Related to error messages

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Improve syntax error message with Hints

2 participants