Make overriding closure methods an error #39498
Closed
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.
Overriding closure methods is a strong sign that the programmer is
confused about the lexical scoping rules for closure methods. (That is,
they expect them to behave like generic functions in top level code).
Make this an error so that people can't get caught out by this.
Helps with #15602. May close it, though we may also want detection in lowering as a more complete solution?
After changing this there were two failing tests so this is likely to be slightly breaking for some user code as well. In particular,
@testset
puts code inside alet
block (#33864) so functions declared inside@testset
become closures.Nevertheless, Julia 1.6 will make this a warning due to the changes in #36609 so people will have some time to adjust.