-
Notifications
You must be signed in to change notification settings - Fork 92
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
Add optional static typing to functions and structs #904
Conversation
Update: I've discovered that structs do not have static typing aswell (again, this is in the parser, not in the VM). So i've made a little update that adds optional static typing to the struct's fields :D |
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.
Cheers!
Could you also add the code which rejects the relevant items during indexing in case type information is specified? Otherwise the compiler will silently accept this even though it's subject to change which could accidentally allow breaking changes to sneak through.
That is currently checked in places like these:
rune/crates/rune/src/indexing/index.rs
Line 231 in a833d25
pub(crate) fn item_fn(idx: &mut Indexer<'_, '_>, mut ast: ast::ItemFn) -> compile::Result<()> { |
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 think the last required component is indexing rejection.
There, i fixed it and i think its now ready to run the tests :D |
Great, now if the type parameters are set, they still need to be rejected during indexing: rune/crates/rune/src/indexing/index.rs Line 231 in a833d25
And here: rune/crates/rune/src/indexing/index.rs Line 922 in a833d25
You can see other types of errors raised in there. Please also add the relevant test cases to make sure type annotations are rejected. You can see for example the attribute rejection test here to see how it can be done: rune/crates/rune/src/tests/attribute.rs Line 92 in a833d25
|
Sure sure! I'll try that :D |
There, i think i've added indexing rejection successfully c: |
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.
There are a few more places you could add if you wanted to, declarations and function arguments come to mind. But looks good for now!
Yay! Niiice! Thank you so much! :D There's probably a lot that i'll add more features to the Parser the more features i start adding to Vune. Thank u for approving my PR and i'm glad this is useful for Rune :D |
Yeah, of course! Thank you! |
This tiny PR adds the option for the parser to detect "-> Type" at the end of the function if its detected.