disallow extending records with functions outside of original scope #48
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.
tl supports the common pattern of adding functions to an empty table without having to declare them beforehand, which is used in module declarations:
A side effect to this was #39, where arbitrary functions could be created by callers of a module, when making a typo while trying to redefine a function (e.g. for a callback, like
love.draw
).This restricts the definition of undeclared functions to the same scope level where a record is declared only. So the above example works, but trying to create new functions from other files don't. to declare functions from other files, you have to declare a record type and declare the function as a field to that record, like this:
Restricting it by scope might be overly restrictive (a simple wrapper
do
block will cause a function to be in a different scope and be rejected) and an alternative to consider could be to do it by file, but there's always the alternative of forward-declaring functions first (liketl
itself does fortl.process
andtl.type_check
for example in lines 2 and 3), so this limitation shouldn't be a show-stopper. So I think this behavior should be fine for now.Fixes #39.