Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply Override Fixit to Variable Declarations #25315

Merged
merged 1 commit into from Jun 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 9 additions & 8 deletions lib/Sema/TypeCheckDeclOverride.cpp
Expand Up @@ -1634,18 +1634,19 @@ static bool checkSingleOverride(ValueDecl *override, ValueDecl *base) {
overrideRequiresKeyword(base) != OverrideRequiresKeyword::Never &&
!override->isImplicit() &&
override->getDeclContext()->getParentSourceFile()) {
// FIXME: rdar://16320042 - For properties, we don't have a useful
// location for the 'var' token. Instead of emitting a bogus fixit, only
// emit the fixit for 'func's.
auto theDiag =
overrideRequiresKeyword(base) == OverrideRequiresKeyword::Always
? diag::missing_override
: diag::missing_override_warn;
if (!isa<VarDecl>(override))
diags.diagnose(override, theDiag)
.fixItInsert(override->getStartLoc(), "override ");
else
diags.diagnose(override, theDiag);

auto diagLoc = override->getStartLoc();
// If dynamic cast to VarDecl succeeds, use the location of its parent
// pattern binding which will return the VarLoc.
if (auto VD = dyn_cast<VarDecl>(override)) {
diagLoc = VD->getParentPatternBinding()->getLoc();
}

diags.diagnose(override, theDiag).fixItInsert(diagLoc, "override ");
diags.diagnose(base, diag::overridden_here);
}

Expand Down
5 changes: 3 additions & 2 deletions test/attr/attr_override.swift
Expand Up @@ -29,6 +29,7 @@ class A {

var v1: Int { return 5 }
var v2: Int { return 5 } // expected-note{{overridden declaration is here}}
internal var v21: Int { return 5 } // expected-note{{overridden declaration is here}}
var v4: String { return "hello" }// expected-note{{attempt to override property here}}
var v5: A { return self }
var v6: A { return self }
Expand Down Expand Up @@ -93,9 +94,9 @@ class B : A {
override func f0() { }
func f1() { } // expected-error{{overriding declaration requires an 'override' keyword}}{{3-3=override }}
override func f2() { } // expected-error{{method does not override any method from its superclass}}

override var v1: Int { return 5 }
var v2: Int { return 5 } // expected-error{{overriding declaration requires an 'override' keyword}}
var v2: Int { return 5 } // expected-error{{overriding declaration requires an 'override' keyword}}{{3-3=override }}
internal var v21: Int { return 5 } // expected-error{{overriding declaration requires an 'override' keyword}}{{12-12=override }}
override var v3: Int { return 5 } // expected-error{{property does not override any property from its superclass}}
override var v4: Int { return 5 } // expected-error{{property 'v4' with type 'Int' cannot override a property with type 'String'}}

Expand Down