-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[AST] #SR-13906 (Improvement) Error Messages #35238
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -235,10 +235,19 @@ static void checkInheritanceClause( | |
// AnyObject is not allowed except on protocols. | ||
if (layout.hasExplicitAnyObject && | ||
!isa<ProtocolDecl>(decl)) { | ||
decl->diagnose(canHaveSuperclass | ||
? diag::inheritance_from_non_protocol_or_class | ||
: diag::inheritance_from_non_protocol, | ||
inheritedTy); | ||
// Check if the inherited type is exclusively AnyObject | ||
// If not, we can be sure of the composition of Protocol(s) with | ||
// AnyObject | ||
if (!layout.isAnyObject()) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it's more important to break up the diagnostic in the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You mean breaking down the ternary operator to if-else for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The intent of the original bug was to fix this particular ternary by providing a more specific message. Its branches are the cause of the confusion here. |
||
decl->diagnose(diag::composition_of_protocol_and_anyobject, | ||
typeDecl->getName(), inheritedTy); | ||
} else { | ||
decl->diagnose(canHaveSuperclass | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the comment left by Codafi, of addressing the else block still needs to be done. |
||
? diag::inheritance_from_non_protocol_or_class | ||
: diag::inheritance_from_non_protocol, | ||
decl->getDescriptiveKind(), inheritedTy); | ||
} | ||
|
||
continue; | ||
} | ||
|
||
|
@@ -342,6 +351,7 @@ static void checkInheritanceClause( | |
decl->diagnose(canHaveSuperclass | ||
? diag::inheritance_from_non_protocol_or_class | ||
: diag::inheritance_from_non_protocol, | ||
decl->getDescriptiveKind(), | ||
inheritedTy); | ||
// FIXME: Note pointing to the declaration 'inheritedTy' references? | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -55,7 +55,7 @@ func testGenericInherit() { | |
} | ||
|
||
|
||
struct SS<T> : T { } // expected-error{{inheritance from non-protocol type 'T'}} | ||
struct SS<T> : T { } // expected-error{{generic struct type cannot inherit from non-protocol type 'T'giy }} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
enum SE<T> : T { case X } // expected-error{{raw type 'T' is not expressible by a string, integer, or floating-point literal}} // expected-error {{SE<T>' declares raw type 'T', but does not conform to RawRepresentable and conformance could not be synthesized}} expected-error{{RawRepresentable conformance cannot be synthesized because raw type 'T' is not Equatable}} | ||
|
||
// Also need Equatable for init?(RawValue) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,13 +30,13 @@ class D3 : Any, A { } // expected-error{{superclass 'A' must appear first in the | |
class D4 : P & P1, A { } // expected-error{{superclass 'A' must appear first in the inheritance clause}}{{18-21=}}{{12-12=A, }} | ||
|
||
// Struct inheriting a class | ||
struct S : A { } // expected-error{{inheritance from non-protocol type 'A'}} | ||
struct S : A { } // expected-error{{struct type cannot inherit from non-protocol type 'A'}} | ||
|
||
// Protocol inheriting a class | ||
protocol Q : A { } | ||
|
||
// Extension inheriting a class | ||
extension C : A { } // expected-error{{inheritance from non-protocol type 'A'}} | ||
extension C : A { } // expected-error{{extension type cannot inherit from non-protocol type 'A'}} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think that there is no such term as |
||
|
||
// Keywords in inheritance clauses | ||
struct S2 : struct { } // expected-error{{expected type}} | ||
|
@@ -56,7 +56,7 @@ class GenericBase<T> {} | |
|
||
class GenericSub<T> : GenericBase<T> {} // okay | ||
|
||
class InheritGenericParam<T> : T {} // expected-error {{inheritance from non-protocol, non-class type 'T'}} | ||
class InheritGenericParam<T> : T {} // expected-error {{generic class type cannot inherit from non-protocol, non-class type 'T'}} | ||
class InheritBody : T { // expected-error {{cannot find type 'T' in scope}} | ||
typealias T = A | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see there is this tailored diagnostic for composition but not a regression test case for exercise it. We should add the respective test :)