Skip to content

Conversation

@rcosta358
Copy link
Collaborator

@rcosta358 rcosta358 commented Nov 4, 2025

Previously, when a @RefinementAlias contained an invalid definition, e.g. missing parameter type, it silently failed parsing and then would return a not found error when it was trying to be used.

Example

@RefinementAlias("Positive(v) { v > 0 }")
public class Example {
    void example() {
        @Refinement("Positive(x)")
        int x = 1; // error
    }
}

Before:

Failed to check refinement at: 

Alias 'Positive' not found
@liquidjava.specification.Refinement("Positive(x)")
int x = 1

After:

Syntax error with message
Alias definitions should be in format <name>(<parameters>) { <definition> }
Found in refinement:
Positive(v) { v > 0 }

@rcosta358 rcosta358 self-assigned this Nov 4, 2025
@rcosta358 rcosta358 added the enhancement New feature or request label Nov 4, 2025
Copy link
Collaborator

@CatarinaGamboa CatarinaGamboa left a comment

Choose a reason for hiding this comment

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

Good short fix, do you think in the future we can pinpoint why it is invalid? Like in this case the type of v is missing right, it could be great to add that so we can be more specific on the issues

@rcosta358
Copy link
Collaborator Author

Yeah sure!

@rcosta358
Copy link
Collaborator Author

rcosta358 commented Nov 5, 2025

The issue is that the parsing doesn't fail here:

public static AliasDTO getAliasDeclaration(String s) throws ParsingException {
  Optional<String> os = getErrors(s);
  if (os.isPresent()) // should fail here
      throw new ParsingException(os.get());
  // ...
}

Since it doesn't throw a ParsingException, we can't the proper error message containing the next token the parser was expecting (a type in this case).

It only fails when it sees that the parse tree is not an alias (by returning null):

public AliasDTO getAlias(ParseTree rc) {
  if (rc instanceof AliasContext) {
      // ...
      return new AliasDTO(name, varTypes, varNames, ref);

  } else if (rc.getChildCount() > 0) {
      int i = rc.getChildCount();
      if (i > 0) {
          return getAlias(rc.getChild(0));
      }
  }
  return null;
}

Fow now I'll just follow the approach done in the ghost declaration parsing:

AliasDTO alias = av.getAlias(rc);
if (alias == null)
    throw new ParsingException("The alias should be in format <name>(<parameters>) { <definition> }");
return alias;

@rcosta358 rcosta358 merged commit d906b45 into liquid-java:main Nov 5, 2025
1 check passed
@rcosta358 rcosta358 deleted the alias-syntax-error branch November 8, 2025 19:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request error messages

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants