Skip to content

Commit 36c8af8

Browse files
authored
Merge pull request #75641 from slavapestov/fix-issue-74651
Sema: Fix crash with property override and almost-valid superclass
2 parents 75eb507 + fefde3b commit 36c8af8

File tree

2 files changed

+11
-15
lines changed

2 files changed

+11
-15
lines changed

lib/Sema/TypeCheckDeclOverride.cpp

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -857,19 +857,6 @@ namespace {
857857

858858
return cachedDeclType;
859859
}
860-
861-
/// Adjust the interface of the given declaration, which is found in
862-
/// a supertype of the given type.
863-
Type getSuperMemberDeclType(ValueDecl *baseDecl) const {
864-
auto selfType = decl->getDeclContext()->getSelfInterfaceType();
865-
if (selfType->getClassOrBoundGenericClass()) {
866-
selfType = selfType->getSuperclass();
867-
assert(selfType && "No superclass type?");
868-
}
869-
870-
return selfType->adjustSuperclassMemberDeclType(
871-
baseDecl, decl, baseDecl->getInterfaceType());
872-
}
873860
};
874861
}
875862

@@ -1283,7 +1270,9 @@ bool OverrideMatcher::checkOverride(ValueDecl *baseDecl,
12831270
}
12841271
} else if (auto property = dyn_cast<VarDecl>(decl)) {
12851272
auto propertyTy = property->getInterfaceType();
1286-
auto parentPropertyTy = getSuperMemberDeclType(baseDecl);
1273+
auto selfType = decl->getDeclContext()->getSelfInterfaceType();
1274+
auto parentPropertyTy = selfType->adjustSuperclassMemberDeclType(
1275+
baseDecl, decl, baseDecl->getInterfaceType());
12871276

12881277
CanType parentPropertyCanTy =
12891278
parentPropertyTy->getReducedType(

test/decl/class/override.swift

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,10 @@ class IUOTestSubclassOkay : IUOTestBaseClass {
236236
override func oneC(_ x: AnyObject) {}
237237
}
238238

239-
class GenericBase<T> {}
239+
class GenericBase<T> { // expected-note{{generic type 'GenericBase' declared here}}
240+
var values: Int { 0 } // expected-note{{attempt to override property here}}
241+
}
242+
240243
class ConcreteDerived: GenericBase<Int> {}
241244

242245
class OverriddenWithConcreteDerived<T> {
@@ -424,3 +427,7 @@ class OverrideTypoSubclass: OverrideTypoBaseClass {
424427
override func foo(_ x: Itn) {} // expected-error {{cannot find type 'Itn' in scope}}
425428
}
426429

430+
// https://github.com/swiftlang/swift/issues/74651
431+
class InvalidSubclass: GenericBase { // expected-error {{reference to generic type 'GenericBase' requires arguments in <...>}}
432+
var values: Float { 0 } // expected-error {{property 'values' with type 'Float' cannot override a property with type 'Int'}}
433+
}

0 commit comments

Comments
 (0)