diff --git a/include/swift/AST/DiagnosticsSema.def b/include/swift/AST/DiagnosticsSema.def index 0b25a26844069..9ce207e558b7c 100644 --- a/include/swift/AST/DiagnosticsSema.def +++ b/include/swift/AST/DiagnosticsSema.def @@ -2964,7 +2964,7 @@ ERROR(dynamic_self_non_method,none, "%select{global|local}0 function cannot return 'Self'", (bool)) ERROR(dynamic_self_invalid,none, - "covariant 'Self' can only appear as the possibly optional type of a " + "covariant 'Self' or 'Self?' can only appear as the type of a " "property, subscript or method result; did you mean '%0'?", (StringRef)) ERROR(dynamic_self_in_mutable_property,none, "mutable property cannot have covariant 'Self' type", ()) @@ -2973,11 +2973,14 @@ ERROR(dynamic_self_in_stored_property,none, ERROR(dynamic_self_in_mutable_subscript,none, "mutable subscript cannot have covariant 'Self' type", ()) ERROR(dynamic_self_invalid_property,none, - "covariant 'Self' can only appear at the top level of property type", ()) + "covariant 'Self' or 'Self?' can only appear at the top level of " + "property type", ()) ERROR(dynamic_self_invalid_subscript,none, - "covariant 'Self' can only appear at the top level of subscript element type", ()) + "covariant 'Self' or 'Self?' can only appear at the top level of " + "subscript element type", ()) ERROR(dynamic_self_invalid_method,none, - "covariant 'Self' can only appear at the top level of method result type", ()) + "covariant 'Self' or 'Self?' can only appear at the top level of " + "method result type", ()) ERROR(dynamic_self_stored_property_init,none, "covariant 'Self' type cannot be referenced from a stored property initializer", ()) ERROR(dynamic_self_default_arg,none, diff --git a/test/decl/ext/generic.swift b/test/decl/ext/generic.swift index c5605cc23e776..8843479880b38 100644 --- a/test/decl/ext/generic.swift +++ b/test/decl/ext/generic.swift @@ -149,7 +149,7 @@ extension Array where Element == String { } extension GenericClass : P3 where T : P3 { } extension GenericClass where Self : P3 { } -// expected-error@-1{{covariant 'Self' can only appear as the possibly optional type of a property, subscript or method result; did you mean 'GenericClass'?}} {{30-34=GenericClass}} +// expected-error@-1{{covariant 'Self' or 'Self?' can only appear as the type of a property, subscript or method result; did you mean 'GenericClass'?}} {{30-34=GenericClass}} // expected-error@-2{{'GenericClass' in conformance requirement does not refer to a generic parameter or associated type}} protocol P4 { diff --git a/test/decl/func/dynamic_self.swift b/test/decl/func/dynamic_self.swift index 867facc840f1b..e56003d684b29 100644 --- a/test/decl/func/dynamic_self.swift +++ b/test/decl/func/dynamic_self.swift @@ -24,9 +24,9 @@ enum E0 { class C0 { func f() -> Self { } // okay - func g(_ ds: Self) { } // expected-error{{covariant 'Self' can only appear as the possibly optional type of a property, subscript or method result; did you mean 'C0'?}} + func g(_ ds: Self) { } // expected-error{{covariant 'Self' or 'Self?' can only appear as the type of a property, subscript or method result; did you mean 'C0'?}} - func h(_ ds: Self) -> Self { } // expected-error{{covariant 'Self' can only appear as the possibly optional type of a property, subscript or method result; did you mean 'C0'?}} + func h(_ ds: Self) -> Self { } // expected-error{{covariant 'Self' or 'Self?' can only appear as the type of a property, subscript or method result; did you mean 'C0'?}} } protocol P0 { diff --git a/test/type/self.swift b/test/type/self.swift index fc3d2de731e08..4355ae739b07e 100644 --- a/test/type/self.swift +++ b/test/type/self.swift @@ -5,7 +5,7 @@ struct S0 { } class C0 { - func foo(_ other: Self) { } // expected-error{{covariant 'Self' can only appear as the possibly optional type of a property, subscript or method result; did you mean 'C0'?}} + func foo(_ other: Self) { } // expected-error{{covariant 'Self' or 'Self?' can only appear as the type of a property, subscript or method result; did you mean 'C0'?}} } enum E0 { @@ -47,7 +47,7 @@ final class FinalMario : Mario { class A { typealias _Self = Self - // expected-error@-1 {{covariant 'Self' can only appear as the possibly optional type of a property, subscript or method result; did you mean 'A'?}} + // expected-error@-1 {{covariant 'Self' or 'Self?' can only appear as the type of a property, subscript or method result; did you mean 'A'?}} let b: Int required init(a: Int) { print("\(Self.self).\(#function)") @@ -55,7 +55,7 @@ class A { b = a } static func z(n: Self? = nil) { - // expected-error@-1 {{covariant 'Self' can only appear as the possibly optional type of a property, subscript or method result; did you mean 'A'?}} + // expected-error@-1 {{covariant 'Self' or 'Self?' can only appear as the type of a property, subscript or method result; did you mean 'A'?}} print("\(Self.self).\(#function)") } class func y() { @@ -130,14 +130,14 @@ class C { // expected-warning@-1 {{conditional cast from 'Self' to 'Self' always succeeds}} } func h(j: () -> Self) -> () -> Self { - // expected-error@-1 {{covariant 'Self' can only appear at the top level of method result type}} + // expected-error@-1 {{covariant 'Self' or 'Self?' can only appear at the top level of method result type}} return { return self } } func i() -> (Self, Self) {} - // expected-error@-1 {{covariant 'Self' can only appear at the top level of method result type}} + // expected-error@-1 {{covariant 'Self' or 'Self?' can only appear at the top level of method result type}} func j() -> Self.Type {} - // expected-error@-1 {{covariant 'Self' can only appear at the top level of method result type}} + // expected-error@-1 {{covariant 'Self' or 'Self?' can only appear at the top level of method result type}} let p0: Self? // expected-error {{stored property cannot have covariant 'Self' type}} var p1: Self? // expected-error {{stored property cannot have covariant 'Self' type}}