Add opt-in inconsistent_default_argument_in_file rule#6796
Open
nenadvulic wants to merge 2 commits into
Open
Conversation
5911061 to
1e4bc4c
Compare
Generated by 🚫 Danger |
Flag overloaded functions declared on the same type (its primary declaration and any extensions of it in the same file) when a shared (label, type) parameter uses divergent default values. Nested types form their own scope; cross-file/semantic cases are left to a future analyzer rule. Issue: realm#6668
1e4bc4c to
9eb5641
Compare
Author
|
@SimplyDanny the rule behaves exactly as scoped in this thread 6668 : grouping by (label, type) within a type's declaration + its extensions in the same file, nested types isolated. All matches are intra-type (no cross-type false matches). The mix of real catches and intentional differences is expected and is the reason for the opt-in default; teams that want the "overloads share defaults" invariant enable it, others aren't affected. |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Adds a new opt-in rule
inconsistent_default_argument_in_file(kind:lint), as discussed in #6668.It flags overloaded functions declared on the same type — the type's primary declaration and any extensions of it in the same file — when a shared
(label, type)parameter uses different default values. This catches accidental default drift across overloads that callers reasonably expect to behave the same, e.g.:Scope
Per the agreement with @SimplyDanny and @rgoldberg in #6668, this is the intentionally small, purely syntactic, single-file variant:
across_one_type: a type's primary declaration plus all extensions of it in the same file are treated as one scope (matched via the fully-qualified lexical type name, e.g.Foo.Bar).separately):Parent.f(…)andParent.Nested.f(…)are functions on different types, so they are never compared — comparing them would produce false positives.Deliberately out of scope here (left to a potential future analyzer rule, so no name clash):
call_default_argumentsandoverride_default_arguments— both need type/symbol resolution unavailable to a syntactic rule.The
_in_filesuffix keeps the name honest about the limitation and leaves room for a fully-general analyzer rule later. Config options floated in the discussion (container_scope,nested_containers,parameter_grouping, …) are intentionally not included yet; they can be layered on additively without breaking the v1 defaults.Examples
Triggering:
Non-triggering (same default, one-sided default, different type, different scope, nested type):
Closes #6668.