Skip to content

Commit 61156e1

Browse files
committed
[Sema] Avoid diagnosing overrides for invalid decls
Invalid decls won't match any overrides in the base class, so avoid diagnosing that they don't override anything.
1 parent 7b71100 commit 61156e1

File tree

3 files changed

+18
-4
lines changed

3 files changed

+18
-4
lines changed

lib/Sema/TypeCheckDeclOverride.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1421,6 +1421,11 @@ bool swift::checkOverrides(ValueDecl *decl) {
14211421
return false;
14221422
}
14231423

1424+
// Don't bother checking any further for invalid decls since they won't match
1425+
// anything.
1426+
if (decl->isInvalid())
1427+
return true;
1428+
14241429
// Set up matching, but bail out if there's nothing to match.
14251430
OverrideMatcher matcher(decl);
14261431
if (!matcher) return false;

test/decl/circularity.swift

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,9 @@ class C3: G1<A>, P {
8686
// expected-error@-2 {{cannot find type 'A' in scope}}
8787
// expected-note@-3 2{{through reference here}}
8888
override func run(a: A) {}
89-
// expected-error@-1 {{method does not override any method from its superclass}}
90-
// expected-error@-2 {{circular reference}}
91-
// expected-note@-3 2 {{through reference here}}
92-
// expected-note@-4 {{while resolving type 'A'}}
89+
// expected-error@-1 {{circular reference}}
90+
// expected-note@-2 2 {{through reference here}}
91+
// expected-note@-3 {{while resolving type 'A'}}
9392
}
9493

9594
// Another case that triggers circular override checking.

test/decl/class/override.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,3 +414,13 @@ open class OpenDerivedFinal : OpenBase {
414414
open class OpenDerivedStatic : OpenBase {
415415
override public static func classMethod() {}
416416
}
417+
418+
// When override matching an invalid decl, avoid emitting
419+
// another error saying it doesn't override anything.
420+
class OverrideTypoBaseClass {
421+
func foo(_ x: Int) {}
422+
}
423+
class OverrideTypoSubclass: OverrideTypoBaseClass {
424+
override func foo(_ x: Itn) {} // expected-error {{cannot find type 'Itn' in scope}}
425+
}
426+

0 commit comments

Comments
 (0)