-
Notifications
You must be signed in to change notification settings - Fork 110
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: improve check over uses of self in forward-declared methods (#642)
### What? - Adds new `Type.is_self` property for identifying a function/method parameter that is `self` - Adds new `string` parameter `name` for passing the name of the body / type being parsed to: - the `ParseBody` type - `parse_newtype` - `parse_record_body` - Passes the record name using the `name` parameter for all cases where `parse_record_body` is called - Updates `parse_argument_type` so that if the argument is named `self`, the type is marked as `is_self = true` - Updates `parse_function_type` so that if the first argument has `is_self == true`, the function type is marked as `is_method = true` - Updates `parse_record_body` so that, before a method is added to the record's fields, it is verified that the first argument matches the type of the record, and if it does not then it is marked as `is_self = false` and the function type as `is_method = false` - Updates `recurse_type` so that the first argument is also recursed in a method if that argument is marked as `is_self == true` - Consolidates the near-indentical `shallow_copy` and `shallow_copy_type` methods into one ### Why? See #638 - this PR allows for forward declaration of methods in records, based on the first argument being named `self` and being correctly typed. This allows for warnings and clearer errors when using types defined in `.d.tl` files, as well as allowing methods to be declared in one scope and then defined in another without losing these warnings. ### Anything else? There is an edge case: the code ``` local record MyRecord<T> add: function(self: MyRecord<integer>, other: MyRecord<integer>) end local first: MyRecord<integer> = {} local second: MyRecord<integer> = {} first.add(second) ``` does not raise a warning, since `add` is not treated as a method for `MyRecord`, even though it could be argued that it should be treated as a method of the type realisation `MyRecord<integer>`. Squashed commits: * feat: adds work-in-progress logic for methods declared inside a record * feat: ensures that functions declared in record bodies are only treated as records if the self parameter is the correct type * chore: consolidates nearly identical shallow_copy and shallow_copy_type methods into one
- Loading branch information
1 parent
0bdec77
commit 67ea51b
Showing
3 changed files
with
321 additions
and
131 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.