diff --git a/include/swift/AST/DiagnosticsSema.def b/include/swift/AST/DiagnosticsSema.def index 0e1bbca76e2..c72e9f5a21a 100644 --- a/include/swift/AST/DiagnosticsSema.def +++ b/include/swift/AST/DiagnosticsSema.def @@ -802,7 +802,8 @@ NOTE(invalid_redecl_implicit_wrapper,none, ERROR(ambiguous_type_base,none, "%0 is ambiguous for type lookup in this context", (DeclNameRef)) ERROR(invalid_member_type,none, - "%0 is not a member type of %1", (DeclNameRef, Type)) + "%0 is not a member type of %1 %2", + (DeclNameRef, DescriptiveDeclKind, FullyQualified)) ERROR(invalid_member_type_suggest,none, "%0 does not have a member type named %1; did you mean %2?", (Type, DeclNameRef, DeclName)) diff --git a/lib/Sema/TypeCheckType.cpp b/lib/Sema/TypeCheckType.cpp index 65211598a65..d45f3e12693 100644 --- a/lib/Sema/TypeCheckType.cpp +++ b/lib/Sema/TypeCheckType.cpp @@ -153,6 +153,17 @@ Type TypeResolution::mapTypeIntoContext(Type type) const { llvm_unreachable("unhandled stage"); } +// FIXME: It would be nice to have a 'DescriptiveTypeKind' abstraction instead. +static DescriptiveDeclKind describeDeclOfType(Type t) { + if (!t) { + return DescriptiveDeclKind::Type; + } + if (auto *NTD = t->getAnyNominal()) { + return NTD->getDescriptiveKind(); + } + return DescriptiveDeclKind::Type; +} + Type TypeResolution::resolveDependentMemberType( Type baseTy, DeclContext *DC, SourceRange baseRange, @@ -211,8 +222,9 @@ Type TypeResolution::resolveDependentMemberType( if (!singleType) { auto name = ref->getNameRef(); auto nameLoc = ref->getNameLoc(); - ctx.Diags.diagnose(nameLoc, diag::invalid_member_type, name, baseTy) - .highlight(baseRange); + const auto kind = describeDeclOfType(baseTy); + ctx.Diags.diagnose(nameLoc, diag::invalid_member_type, name, kind, baseTy) + .highlight(baseRange); corrections.noteAllCandidates(); return ErrorType::get(ctx); @@ -1160,8 +1172,10 @@ static Type diagnoseUnknownType(TypeResolution resolution, // Qualified lookup case. if (!parentType->mayHaveMembers()) { - diags.diagnose(comp->getNameLoc(), diag::invalid_member_type, - comp->getNameRef(), parentType) + const auto kind = describeDeclOfType(parentType); + diags + .diagnose(comp->getNameLoc(), diag::invalid_member_type, + comp->getNameRef(), kind, parentType) .highlight(parentRange); return ErrorType::get(ctx); } @@ -1214,9 +1228,11 @@ static Type diagnoseUnknownType(TypeResolution resolution, parentType) .highlight(parentRange); } else { - diags.diagnose(comp->getNameLoc(), diag::invalid_member_type, - comp->getNameRef(), parentType) - .highlight(parentRange); + const auto kind = describeDeclOfType(parentType); + diags + .diagnose(comp->getNameLoc(), diag::invalid_member_type, + comp->getNameRef(), kind, parentType) + .highlight(parentRange); // Note where the type was defined, this can help diagnose if the user // expected name lookup to find a module when there's a conflicting type. if (auto typeDecl = parentType->getNominalOrBoundGenericNominal()) { diff --git a/test/AutoDiff/Sema/differentiable_attr_type_checking.swift b/test/AutoDiff/Sema/differentiable_attr_type_checking.swift index dfb702ecc89..11f82032c3b 100644 --- a/test/AutoDiff/Sema/differentiable_attr_type_checking.swift +++ b/test/AutoDiff/Sema/differentiable_attr_type_checking.swift @@ -632,7 +632,7 @@ class Super: Differentiable { // TODO(TF-632): Fix "'TangentVector' is not a member type of 'Self'" diagnostic. // The underlying error should appear instead: // "covariant 'Self' can only appear at the top level of method result type". - // expected-error @+1 2 {{'TangentVector' is not a member type of 'Self'}} + // expected-error @+1 2 {{'TangentVector' is not a member type of type 'Self'}} func vjpDynamicSelfResult() -> (Self, (Self.TangentVector) -> Self.TangentVector) { return (self, { $0 }) } diff --git a/test/Constraints/invalid_archetype_constraint.swift b/test/Constraints/invalid_archetype_constraint.swift index 6b743b0f5b0..2626e167ce2 100644 --- a/test/Constraints/invalid_archetype_constraint.swift +++ b/test/Constraints/invalid_archetype_constraint.swift @@ -19,6 +19,6 @@ struct A2 : P { typealias Element = T } -func toA(_ s: S) -> AT where AT.Element == S.Generator.Element { // expected-error{{'Generator' is not a member type of 'S'}} +func toA(_ s: S) -> AT where AT.Element == S.Generator.Element { // expected-error{{'Generator' is not a member type of type 'S'}} return AT() } diff --git a/test/Constraints/invalid_constraint_lookup.swift b/test/Constraints/invalid_constraint_lookup.swift index 0f7a03603ae..4c47990fd6f 100644 --- a/test/Constraints/invalid_constraint_lookup.swift +++ b/test/Constraints/invalid_constraint_lookup.swift @@ -25,6 +25,6 @@ protocol _Collection { protocol Collection : _Collection, Sequence { subscript(i: Index) -> Iterator.Element {get set } } -func insertionSort (_ elements: inout C, i: C.Index) { // expected-error {{cannot find type 'Mutable' in scope}} expected-error {{'Index' is not a member type of 'C'}} - var x: C.Iterator.Element = elements[i] // expected-error {{'Iterator' is not a member type of 'C'}} +func insertionSort (_ elements: inout C, i: C.Index) { // expected-error {{cannot find type 'Mutable' in scope}} expected-error {{'Index' is not a member type of type 'C'}} + var x: C.Iterator.Element = elements[i] // expected-error {{'Iterator' is not a member type of type 'C'}} } diff --git a/test/Constraints/same_types.swift b/test/Constraints/same_types.swift index cb479f1bfad..1241ca3252f 100644 --- a/test/Constraints/same_types.swift +++ b/test/Constraints/same_types.swift @@ -141,7 +141,7 @@ func test8b(_ t: T, u: U) } // rdar://problem/19137463 -func rdar19137463(_ t: T) where T.a == T {} // expected-error{{'a' is not a member type of 'T'}} +func rdar19137463(_ t: T) where T.a == T {} // expected-error{{'a' is not a member type of type 'T'}} rdar19137463(1) diff --git a/test/Generics/associated_type_typo.swift b/test/Generics/associated_type_typo.swift index 9ac717e3861..8b596d3c88e 100644 --- a/test/Generics/associated_type_typo.swift +++ b/test/Generics/associated_type_typo.swift @@ -79,4 +79,4 @@ class D { typealias BElement = Int // expected-note{{did you mean 'BElement'?}} } -func typoSuperclass2(_: T, _: T.Element) { } // expected-error{{'Element' is not a member type of 'T'}} +func typoSuperclass2(_: T, _: T.Element) { } // expected-error{{'Element' is not a member type of type 'T'}} diff --git a/test/Generics/function_defs.swift b/test/Generics/function_defs.swift index 0a271eec4f2..1ed1d43e3b7 100644 --- a/test/Generics/function_defs.swift +++ b/test/Generics/function_defs.swift @@ -290,7 +290,7 @@ func sameTypeEq(_: T) where T = T {} // expected-error{{use '==' for same-typ func badTypeConformance1(_: T) where Int : EqualComparable {} // expected-error{{type 'Int' in conformance requirement does not refer to a generic parameter or associated type}} -func badTypeConformance2(_: T) where T.Blarg : EqualComparable { } // expected-error{{'Blarg' is not a member type of 'T'}} +func badTypeConformance2(_: T) where T.Blarg : EqualComparable { } // expected-error{{'Blarg' is not a member type of type 'T'}} func badTypeConformance3(_: T) where (T) -> () : EqualComparable { } // expected-error@-1{{type '(T) -> ()' in conformance requirement does not refer to a generic parameter or associated type}} diff --git a/test/Generics/generic_types.swift b/test/Generics/generic_types.swift index b0f44a96adb..b961e4a5abd 100644 --- a/test/Generics/generic_types.swift +++ b/test/Generics/generic_types.swift @@ -199,7 +199,7 @@ struct XParam { // expected-note{{'XParam' declared here}} } } -var xp : XParam.T = Int() // expected-error{{'T' is not a member type of 'XParam'}} +var xp : XParam.T = Int() // expected-error{{'T' is not a member type of generic struct 'generic_types.XParam'}} // Diagnose failure to meet a superclass requirement. class X1 { } @@ -237,11 +237,11 @@ class Bottom> {} // Invalid inheritance clause struct UnsolvableInheritance1 {} -// expected-error@-1 {{'A' is not a member type of 'T'}} +// expected-error@-1 {{'A' is not a member type of type 'T'}} struct UnsolvableInheritance2 {} -// expected-error@-1 {{'A' is not a member type of 'U'}} -// expected-error@-2 {{'A' is not a member type of 'T'}} +// expected-error@-1 {{'A' is not a member type of type 'U'}} +// expected-error@-2 {{'A' is not a member type of type 'T'}} enum X7 where X7.X : G { case X } // expected-error{{enum case 'X' is not a member type of 'X7'}} // expected-error@-1{{cannot find type 'G' in scope}} diff --git a/test/Generics/invalid.swift b/test/Generics/invalid.swift index 57578f59a54..4ac99bb950a 100644 --- a/test/Generics/invalid.swift +++ b/test/Generics/invalid.swift @@ -79,7 +79,7 @@ func badDiagnostic3() { // Crash with missing nested type inside concrete type class OuterGeneric { class InnerGeneric where U:OuterGeneric { - // expected-error@-1 {{'NoSuchType' is not a member type of 'T'}} + // expected-error@-1 {{'NoSuchType' is not a member type of type 'T'}} func method() { _ = method } @@ -107,10 +107,10 @@ class P { // SR-5579 protocol Foo { - associatedtype Bar where Bar.Nonsense == Int // expected-error{{'Nonsense' is not a member type of 'Self.Bar'}} + associatedtype Bar where Bar.Nonsense == Int // expected-error{{'Nonsense' is not a member type of type 'Self.Bar'}} } -protocol Wibble : Foo where Bar.EvenMoreNonsense == Int { } // expected-error{{'EvenMoreNonsense' is not a member type of 'Self.Bar'}} +protocol Wibble : Foo where Bar.EvenMoreNonsense == Int { } // expected-error{{'EvenMoreNonsense' is not a member type of type 'Self.Bar'}} // rdar://45271500 - failure to emit a diagnostic enum Cat {} diff --git a/test/Interop/Cxx/class/access-specifiers-typechecker.swift b/test/Interop/Cxx/class/access-specifiers-typechecker.swift index 290b52f69f7..1c4c396d548 100644 --- a/test/Interop/Cxx/class/access-specifiers-typechecker.swift +++ b/test/Interop/Cxx/class/access-specifiers-typechecker.swift @@ -30,14 +30,14 @@ v.PrivateMemberVar = 1 // expected-error {{value of type 'PublicPrivate' has no PublicPrivate.PrivateStaticMemberVar = 1 // expected-error {{'PublicPrivate' has no member 'PrivateStaticMemberVar'}} v.privateMemberFunc() // expected-error {{value of type 'PublicPrivate' has no member 'privateMemberFunc'}} -var privateTypedefVar: PublicPrivate.PrivateTypedef // expected-error {{'PrivateTypedef' is not a member type of 'PublicPrivate'}} -var privateStructVar: PublicPrivate.PrivateStruct // expected-error {{'PrivateStruct' is not a member type of 'PublicPrivate'}} -var privateEnumVar: PublicPrivate.PrivateEnum // expected-error {{'PrivateEnum' is not a member type of 'PublicPrivate'}} +var privateTypedefVar: PublicPrivate.PrivateTypedef // expected-error {{'PrivateTypedef' is not a member type of struct 'AccessSpecifiers.PublicPrivate'}} +var privateStructVar: PublicPrivate.PrivateStruct // expected-error {{'PrivateStruct' is not a member type of struct 'AccessSpecifiers.PublicPrivate'}} +var privateEnumVar: PublicPrivate.PrivateEnum // expected-error {{'PrivateEnum' is not a member type of struct 'AccessSpecifiers.PublicPrivate'}} // TODO: PrivateEnumValue1 and PrivateAnonymousEnumValue1 give the expected // error, but only because these types of enums (private or public) aren't // currently imported at all. Once that is fixed, remove this TODO. print(PublicPrivate.PrivateEnumValue1) // expected-error {{'PublicPrivate' has no member 'PrivateEnumValue1'}} print(PublicPrivate.PrivateAnonymousEnumValue1) // expected-error {{'PublicPrivate' has no member 'PrivateAnonymousEnumValue1'}} -var privateClosedEnumVar: PublicPrivate.PrivateClosedEnum // expected-error {{'PrivateClosedEnum' is not a member type of 'PublicPrivate'}} -var privateOpenEnumVar: PublicPrivate.PrivateOpenEnum // expected-error {{'PrivateOpenEnum' is not a member type of 'PublicPrivate'}} -var privateFlagEnumVar: PublicPrivate.PrivateFlagEnum // expected-error {{'PrivateFlagEnum' is not a member type of 'PublicPrivate'}} +var privateClosedEnumVar: PublicPrivate.PrivateClosedEnum // expected-error {{'PrivateClosedEnum' is not a member type of struct 'AccessSpecifiers.PublicPrivate'}} +var privateOpenEnumVar: PublicPrivate.PrivateOpenEnum // expected-error {{'PrivateOpenEnum' is not a member type of struct 'AccessSpecifiers.PublicPrivate'}} +var privateFlagEnumVar: PublicPrivate.PrivateFlagEnum // expected-error {{'PrivateFlagEnum' is not a member type of struct 'AccessSpecifiers.PublicPrivate'}} diff --git a/test/Sema/diag_module_conflict_with_type.swift b/test/Sema/diag_module_conflict_with_type.swift index db7c485142f..e49b4e2942f 100644 --- a/test/Sema/diag_module_conflict_with_type.swift +++ b/test/Sema/diag_module_conflict_with_type.swift @@ -16,7 +16,7 @@ import SecondModule public func f(_ x: ModuleType.MyStruct) {} -// CHECK: error: 'MyStruct' is not a member type of 'ModuleType' +// CHECK: error: 'MyStruct' is not a member type of struct 'SecondModule.ModuleType' // CHECK: SecondModule.ModuleType:1:15: note: 'ModuleType' declared here // CHECK: public struct ModuleType { // CHECK: ^ diff --git a/test/decl/nested/type_in_function.swift b/test/decl/nested/type_in_function.swift index 6445592a1de..be79256cd8c 100644 --- a/test/decl/nested/type_in_function.swift +++ b/test/decl/nested/type_in_function.swift @@ -128,7 +128,7 @@ struct OuterGenericStruct { func genericFunction(t: T) { class First : Second.UnknownType { } // expected-error@-1 {{type 'First' cannot be nested in generic function 'genericFunction(t:)'}} - // expected-error@-2 {{'UnknownType' is not a member type of 'Second'}} + // expected-error@-2 {{'UnknownType' is not a member type of generic class 'type_in_function.Second'}} class Second : Second { } // expected-note{{'Second' declared here}} // expected-error@-1 {{type 'Second' cannot be nested in generic function 'genericFunction(t:)'}} // expected-error@-2 {{'Second' inherits from itself}} diff --git a/test/decl/protocol/recursive_requirement.swift b/test/decl/protocol/recursive_requirement.swift index 30cd1a03976..dc6528f6bf0 100644 --- a/test/decl/protocol/recursive_requirement.swift +++ b/test/decl/protocol/recursive_requirement.swift @@ -82,8 +82,8 @@ struct Epsilon // expected-warning{{redundant conformance constraint 'U': 'Gamma'}} // expected-note@-1{{conformance constraint 'T': 'Alpha' implied here}} - where T.Beta == U, // expected-error{{'Beta' is not a member type of 'T'}} - U.Delta == T {} // expected-error{{'Delta' is not a member type of 'U'}} + where T.Beta == U, // expected-error{{'Beta' is not a member type of type 'T'}} + U.Delta == T {} // expected-error{{'Delta' is not a member type of type 'U'}} // ----- diff --git a/test/decl/protocol/special/coding/class_codable_member_type_lookup.swift b/test/decl/protocol/special/coding/class_codable_member_type_lookup.swift index 93299fc5dd9..64a1d7f0333 100644 --- a/test/decl/protocol/special/coding/class_codable_member_type_lookup.swift +++ b/test/decl/protocol/special/coding/class_codable_member_type_lookup.swift @@ -184,10 +184,10 @@ struct NonSynthesizedClass : Codable { // expected-note 4 {{'NonSynthesizedClass // Qualified type lookup should clearly fail -- we shouldn't get a synthesized // type here. - public func qualifiedFoo(_ key: NonSynthesizedClass.CodingKeys) {} // expected-error {{'CodingKeys' is not a member type of 'NonSynthesizedClass'}} - internal func qualifiedBar(_ key: NonSynthesizedClass.CodingKeys) {} // expected-error {{'CodingKeys' is not a member type of 'NonSynthesizedClass'}} - fileprivate func qualfiedBaz(_ key: NonSynthesizedClass.CodingKeys) {} // expected-error {{'CodingKeys' is not a member type of 'NonSynthesizedClass'}} - private func qualifiedQux(_ key: NonSynthesizedClass.CodingKeys) {} // expected-error {{'CodingKeys' is not a member type of 'NonSynthesizedClass'}} + public func qualifiedFoo(_ key: NonSynthesizedClass.CodingKeys) {} // expected-error {{'CodingKeys' is not a member type of struct 'class_codable_member_type_lookup.NonSynthesizedClass'}} + internal func qualifiedBar(_ key: NonSynthesizedClass.CodingKeys) {} // expected-error {{'CodingKeys' is not a member type of struct 'class_codable_member_type_lookup.NonSynthesizedClass'}} + fileprivate func qualfiedBaz(_ key: NonSynthesizedClass.CodingKeys) {} // expected-error {{'CodingKeys' is not a member type of struct 'class_codable_member_type_lookup.NonSynthesizedClass'}} + private func qualifiedQux(_ key: NonSynthesizedClass.CodingKeys) {} // expected-error {{'CodingKeys' is not a member type of struct 'class_codable_member_type_lookup.NonSynthesizedClass'}} // Unqualified lookups should find the public top-level CodingKeys type. public func unqualifiedFoo(_ key: CodingKeys) { print(CodingKeys.topLevel) } diff --git a/test/decl/protocol/special/coding/struct_codable_member_type_lookup.swift b/test/decl/protocol/special/coding/struct_codable_member_type_lookup.swift index de467dc05f6..3aa47f47f1a 100644 --- a/test/decl/protocol/special/coding/struct_codable_member_type_lookup.swift +++ b/test/decl/protocol/special/coding/struct_codable_member_type_lookup.swift @@ -184,10 +184,10 @@ struct NonSynthesizedStruct : Codable { // expected-note 4 {{'NonSynthesizedStru // Qualified type lookup should clearly fail -- we shouldn't get a synthesized // type here. - public func qualifiedFoo(_ key: NonSynthesizedStruct.CodingKeys) {} // expected-error {{'CodingKeys' is not a member type of 'NonSynthesizedStruct'}} - internal func qualifiedBar(_ key: NonSynthesizedStruct.CodingKeys) {} // expected-error {{'CodingKeys' is not a member type of 'NonSynthesizedStruct'}} - fileprivate func qualfiedBaz(_ key: NonSynthesizedStruct.CodingKeys) {} // expected-error {{'CodingKeys' is not a member type of 'NonSynthesizedStruct'}} - private func qualifiedQux(_ key: NonSynthesizedStruct.CodingKeys) {} // expected-error {{'CodingKeys' is not a member type of 'NonSynthesizedStruct'}} + public func qualifiedFoo(_ key: NonSynthesizedStruct.CodingKeys) {} // expected-error {{'CodingKeys' is not a member type of struct 'struct_codable_member_type_lookup.NonSynthesizedStruct'}} + internal func qualifiedBar(_ key: NonSynthesizedStruct.CodingKeys) {} // expected-error {{'CodingKeys' is not a member type of struct 'struct_codable_member_type_lookup.NonSynthesizedStruct'}} + fileprivate func qualfiedBaz(_ key: NonSynthesizedStruct.CodingKeys) {} // expected-error {{'CodingKeys' is not a member type of struct 'struct_codable_member_type_lookup.NonSynthesizedStruct'}} + private func qualifiedQux(_ key: NonSynthesizedStruct.CodingKeys) {} // expected-error {{'CodingKeys' is not a member type of struct 'struct_codable_member_type_lookup.NonSynthesizedStruct'}} // Unqualified lookups should find the public top-level CodingKeys type. public func unqualifiedFoo(_ key: CodingKeys) { print(CodingKeys.topLevel) } diff --git a/test/decl/typealias/dependent_types.swift b/test/decl/typealias/dependent_types.swift index 4334f3d7173..a59e1809fe7 100644 --- a/test/decl/typealias/dependent_types.swift +++ b/test/decl/typealias/dependent_types.swift @@ -34,14 +34,14 @@ struct GenericStruct { // expected-note 3{{generic type 'GenericStruct' decla func methodTwo() -> MetaAlias {} func methodOne() -> Alias.BadType {} - // expected-error@-1 {{'BadType' is not a member type of 'GenericStruct.Alias'}} + // expected-error@-1 {{'BadType' is not a member type of type 'dependent_types.GenericStruct.Alias'}} func methodTwo() -> MetaAlias.BadType {} - // expected-error@-1 {{'BadType' is not a member type of 'GenericStruct.MetaAlias'}} + // expected-error@-1 {{'BadType' is not a member type of type 'dependent_types.GenericStruct.MetaAlias'}} var propertyOne: Alias.BadType - // expected-error@-1 {{'BadType' is not a member type of 'GenericStruct.Alias' (aka 'T')}} + // expected-error@-1 {{'BadType' is not a member type of type 'dependent_types.GenericStruct.Alias' (aka 'T')}} var propertyTwo: MetaAlias.BadType - // expected-error@-1 {{'BadType' is not a member type of 'GenericStruct.MetaAlias' (aka 'T.Type')}} + // expected-error@-1 {{'BadType' is not a member type of type 'dependent_types.GenericStruct.MetaAlias' (aka 'T.Type')}} } // This was accepted in Swift 3.0 and sort of worked... but we can't diff --git a/validation-test/compiler_crashers_2_fixed/0159-rdar40009245.swift b/validation-test/compiler_crashers_2_fixed/0159-rdar40009245.swift index d12abc8df6b..9becb7b44a2 100644 --- a/validation-test/compiler_crashers_2_fixed/0159-rdar40009245.swift +++ b/validation-test/compiler_crashers_2_fixed/0159-rdar40009245.swift @@ -2,7 +2,7 @@ protocol P { associatedtype A : P where A.X == Self - // expected-error@-1{{'X' is not a member type of 'Self.A}} + // expected-error@-1{{'X' is not a member type of type 'Self.A'}} associatedtype X : P where P.A == Self // expected-error@-1{{associated type 'A' can only be used with a concrete type or generic parameter base}} } diff --git a/validation-test/compiler_crashers_fixed/00053-std-function-func-swift-type-subst.swift b/validation-test/compiler_crashers_fixed/00053-std-function-func-swift-type-subst.swift index b1c826c6285..60973dcde6c 100644 --- a/validation-test/compiler_crashers_fixed/00053-std-function-func-swift-type-subst.swift +++ b/validation-test/compiler_crashers_fixed/00053-std-function-func-swift-type-subst.swift @@ -10,5 +10,5 @@ // Issue found by https://github.com/julasamer (julasamer) -struct c where d.c == e { // expected-error {{cannot find type 'b' in scope}} expected-error {{'c' is not a member type of 'd'}} +struct c where d.c == e { // expected-error {{cannot find type 'b' in scope}} expected-error {{'c' is not a member type of type 'd'}} }