Skip to content

Commit 2753fc5

Browse files
committed
Diags: Use the declared type for diagnosing inheritance from final class
1 parent 7b787a6 commit 2753fc5

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
@@ -1943,7 +1943,8 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
19431943
bool isInvalidSuperclass = false;
19441944

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

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)