-
Notifications
You must be signed in to change notification settings - Fork 18
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
Functions #19
Conversation
|
||
@Override | ||
public CompletableFuture<?> getValue(EvalContext context) { | ||
return null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
throw?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
if (fun instanceof OpelAsyncFunction) { | ||
return ((OpelAsyncFunction) fun).apply(argsGroup.getListOfValues(context)); | ||
} | ||
throw new OpelException("Can use '" + fun.getClass().getSimpleName() + "' as a function"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
} | ||
|
||
Rule FunctionBody() { | ||
return FirstOf( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not:
return FirstOf(
Expression(),
Sequence("{ ", Body(), "} "), push(pop()));
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
enough is
return FirstOf(
Expression(),
Sequence("{ ", Body(), "} "));
"val fun = (x, y) -> x*y; fun(2, 3, 4, 5)" || 6 | ||
} | ||
|
||
def 'should avoid access to val defined in function outsite its'() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can add similar test showing that local val declaration doesn't change outer val e.g.
val x = 10;
val y = (a) -> {
val x = 5;
x * a;
}(5)
assert x == 10
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
test added
|
||
then: | ||
def ex = thrown ExecutionException | ||
ex.cause instanceof OpelException |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't like the fact that we only check if OpelException
was thrown while cause is completely ignored. I can modify the first case to val fun = x -> x*x; fun(4) * 'a'
and this test will pass. Maybe it's a good time to introduce hierarchy of exceptions or check for sufficient messages in tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
exception hierarchy sound good.
I can do this in separate PR
No description provided.