Skip to content

Commit 291ddb7

Browse files
Merge pull request swiftlang#31504 from AnthonyLatsis/final-superclass-nested
Diags: Use the declared type for diagnosing inheritance from final class
2 parents 6b14c2a + 2753fc5 commit 291ddb7

File tree

3 files changed

+8
-2
lines changed

3 files changed

+8
-2
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2536,7 +2536,7 @@ NOTE(superclass_here,none,"superclass is declared here", ())
25362536
ERROR(superclass_of_open_not_open,none,
25372537
"superclass %0 of open class must be open", (Type))
25382538
ERROR(inheritance_from_final_class,none,
2539-
"inheritance from a final class %0", (Identifier))
2539+
"inheritance from a final class %0", (Type))
25402540
ERROR(inheritance_from_unspecialized_objc_generic_class,none,
25412541
"inheritance from a generic Objective-C class %0 must bind "
25422542
"type parameters of %0 to specific concrete types", (Identifier))

lib/Sema/TypeCheckDeclPrimary.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1942,7 +1942,8 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
19421942
bool isInvalidSuperclass = false;
19431943

19441944
if (Super->isFinal()) {
1945-
CD->diagnose(diag::inheritance_from_final_class, Super->getName());
1945+
CD->diagnose(diag::inheritance_from_final_class,
1946+
Super->getDeclaredType());
19461947
// FIXME: should this really be skipping the rest of decl-checking?
19471948
return;
19481949
}

test/attr/attr_final.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,3 +81,8 @@ class Sub2 : Super2 { //// expected-error{{inheritance from a final class 'Super
8181

8282
final override init() {} // expected-error {{'final' modifier cannot be applied to this declaration}} {{3-9=}}
8383
}
84+
85+
struct Box<T> {
86+
final class Super3 {}
87+
}
88+
class Sub3: Box<Int>.Super3 {} // expected-error{{inheritance from a final class 'Box.Super3'}}

0 commit comments

Comments
 (0)