Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ public Boolean visitRvalue(Java.Rvalue rv) throws Exception {
return true;
}
}
} else if (n.identifiers.length == 1 && mi.arguments.length == 0 && variableValidator.isValid(n.identifiers[0])) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Why was this added it seems like this tries to support a method invocation pattern?

Copy link
Copy Markdown
Author

@OlKir OlKir Oct 2, 2025

Choose a reason for hiding this comment

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

Codex:

I added that branch in core/src/main/java/com/graphhopper/routing/weighting/custom/ConditionalExpressionVisitor.java:108 because, while testing the refactored custom-model caching, Janino sometimes reports the target of an ordinal() call as a single identifier. For expressions like track_type.ordinal() in the built-in models (e.g. motorcycle.json), mi.target.toRvalue() now yields an AmbiguousName with length 1, so our earlier logic never recorded track_type as a used variable and the parser rejected the condition (“… not available”). The new else if just mirrors the existing road_class.ordinal() case for that AST shape so we still accept the expression and we add the variable to guessedVariables, ensuring the enum accessor is created when the model is re-used from the cache.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

For me it's a quick fix for .ordinal() operation. I'm not sure if we use it. But might be useful in future:

change is not specific to track_type; it kicks in whenever Janino gives us a zero-argument method call whose target reduces to a single identifier that the validator accepts. So any bike-oriented custom model that ever does something like bike_network.ordinal() (or a similar accessor on a bike-specific encoded value) now stays valid and keeps the variable in guessedVariables, ensuring the lookup/accessor is built correctly. Even though the shipped bike models don’t currently rely on .ordinal(), they’re covered automatically if we add such expressions later.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

The fact that core tests are passing without this addition kind of confirms the statement.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Hmm alright sounds good to me

// track_type.ordinal()
result.guessedVariables.add(n.identifiers[0]);
return true;
}
}
invalidMessage = mi.methodName + " is an illegal method in a conditional expression";
Expand Down
Loading
Loading