Feature/record body declared methods #642
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What?
Type.is_self
property for identifying a function/method parameter that isself
string
parametername
for passing the name of the body / type being parsed to:ParseBody
typeparse_newtype
parse_record_body
name
parameter for all cases whereparse_record_body
is calledparse_argument_type
so that if the argument is namedself
, the type is marked asis_self = true
parse_function_type
so that if the first argument hasis_self == true
, the function type is marked asis_method = true
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 asis_self = false
and the function type asis_method = false
recurse_type
so that the first argument is also recursed in a method if that argument is marked asis_self == true
shallow_copy
andshallow_copy_type
methods into oneWhy?
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 which may need discussion: the code
does not raise a warning, since
add
is not treated as a method forMyRecord
, even though it could be argued that it should be treated as a method of the type realisationMyRecord<integer>
.I have a vague idea of how this could be achieved if we want this behaviour, but haven't been able to properly implement it yet.
Let me know whether it is fine that there is no warning in this situation, whether this can go into a separate issue / PR, or whether I should try to resolve it in this PR.