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

Painless: improve error message on non-constant #68517

Merged
merged 2 commits into from
Feb 4, 2021
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 @@ -841,12 +841,17 @@ private void replaceCallWithConstant(
Object[] args = new Object[irInvokeCallMemberNode.getArgumentNodes().size()];
for (int i = 0; i < irInvokeCallMemberNode.getArgumentNodes().size(); i++) {
ExpressionNode argNode = irInvokeCallMemberNode.getArgumentNodes().get(i);
if (argNode instanceof ConstantNode == false) {
IRDConstant constantDecoration = argNode.getDecoration(IRDConstant.class);
if (constantDecoration == null) {
// TODO find a better string to output
throw irInvokeCallMemberNode.getLocation()
.createError(new IllegalArgumentException("all arguments must be constant but the [" + (i + 1) + "] argument isn't"));
.createError(
new IllegalArgumentException(
"all arguments to [" + javaMethod.getName() + "] must be constant but the [" + (i + 1) + "] argument isn't"
)
);
}
args[i] = ((ConstantNode) argNode).getDecorationValue(IRDConstant.class);
args[i] = constantDecoration.getValue();
}
Object result;
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ public void testClassMethodCompileTimeOnlyVariableParams() {
IllegalArgumentException.class,
() -> scriptEngine.compile(null, "def a = 2; classMul(2, a)", BindingsTestScript.CONTEXT, Collections.emptyMap())
);
assertThat(e.getMessage(), equalTo("all arguments must be constant but the [2] argument isn't"));
assertThat(e.getMessage(), equalTo("all arguments to [classMul] must be constant but the [2] argument isn't"));
}

public void testClassMethodCompileTimeOnlyThrows() {
Expand Down Expand Up @@ -240,7 +240,7 @@ public void testInstanceMethodCompileTimeOnlyVariableParams() {
IllegalArgumentException.class,
() -> scriptEngine.compile(null, "def a = 2; instanceMul(a, 2)", BindingsTestScript.CONTEXT, Collections.emptyMap())
);
assertThat(e.getMessage(), equalTo("all arguments must be constant but the [1] argument isn't"));
assertThat(e.getMessage(), equalTo("all arguments to [instanceMul] must be constant but the [1] argument isn't"));
}

public void testCompileTimeOnlyParameterFoldedToConstant() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ fetch:
---
mutable pattern:
- do:
catch: /all arguments must be constant but the \[1\] argument isn't/
catch: /all arguments to \[grok\] must be constant but the \[1\] argument isn't/
search:
index: http_logs
body:
Expand Down