-
Notifications
You must be signed in to change notification settings - Fork 83
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
support for optional arguments #260
Conversation
Maybe we need also a test? |
Sure, I'll write some 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.
First review looking good. Some minor changes required
Co-authored-by: Phoenix Himself <[email protected]>
Co-authored-by: Phoenix Himself <[email protected]>
Co-authored-by: Phoenix Himself <[email protected]>
Co-authored-by: Phoenix Himself <[email protected]>
Co-authored-by: Phoenix Himself <[email protected]>
Co-authored-by: Phoenix Himself <[email protected]>
Co-authored-by: Phoenix Himself <[email protected]>
Co-authored-by: Phoenix Himself <[email protected]>
@b1ek can you check if this PR is ready? |
sorry, i dont have the time rn i will take a look tomorrow tho |
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.
are the types supposed to be lazily evaluated? iirc that has not been done in any part of the project yet
the following code prints abc
:
fun a(a = 123) {
echo a
}
a("abc")
actually, nevermind. it is not a lazy evaluation thing, its that it doesnt automatically get assigned the |
So this PR can be approved or there is something pending @b1ek? Can be moved to a different ticket? |
no, there is an issue with it. thats what is meant by "requested changes": either changes have to be made or the review to be dismissed |
I wasn't sure because of your next message. |
@b1ek What is the expected behavior? The problem with assigning a type to an optional argument which isn't explicitly typed is that the rest of the arguments would then have themselves to be typed. That's why I didn't enforce anything here. |
the problem is not that i have expected it to behave like something, the problem is that the PR does not explain this behavior. if you are adding a new feature that changes compiler behavior (or pretty much any other code change tbh), it must be well explained in the PR and tested |
I see. If one wrote the following (without optional arguments) :
They would get the same error as if they did this (with an optional argument)
I want to make sure I'm writing the right kind of test. Do you need one which illustrates what I have just stated? Thank you. |
@ramseyharrison explain how you want it to work with different default & actual type in the description and cover it with a test, then re request the reviews |
I think that this looks good enough. We can improve the erroring system for optional arguments in a separate ticket. |
fn optional_argument_generic(){ | ||
let code = " | ||
fun echo_var(a = 100){ | ||
echo a |
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.
@Ph0enixKM im not sure how exactly docs are published to the site, but please make sure that these shenanigans are properly explained
added support for optional arguments. a regular argument cannot follow an optional argument, so something like
raises an error. It's during the parsing of an invocation that missing arguments in the invocation are replaced with the default arguments parsed during definition. Once we determine the location of the first missing argument, all the default arguments which follow are also passed to the invocation. This is why we can't interleave optional and non-optionals.
EDIT :
In response to @b1ek 's comment, I confirm that since in the following example, the argument
arg1
is generic, despite holding an optional argument, any argument type can be passed to it.So the following are valid calls :
echo_var(100)
,echo_var("test")
.If the argument however is typed,
Then
echo_var("test")
raises an error as expected.