diff --git a/include/swift/AST/PrintOptions.h b/include/swift/AST/PrintOptions.h index d9ef12a86c133..722d9cd459135 100644 --- a/include/swift/AST/PrintOptions.h +++ b/include/swift/AST/PrintOptions.h @@ -553,6 +553,12 @@ struct PrintOptions { /// Whether to always desugar optional types from `base_type?` to `Optional` bool AlwaysDesugarOptionalTypes = false; + /// Whether to always print explicit `Pack{...}` around pack + /// types. + /// + /// This is set to \c false for diagnostic arguments. + bool PrintExplicitPackTypes = true; + /// \see ShouldQualifyNestedDeclarations enum class QualifyNestedDeclarations { Never, @@ -606,6 +612,7 @@ struct PrintOptions { /// The print options used for formatting diagnostic arguments. static PrintOptions forDiagnosticArguments() { PrintOptions result; + result.PrintExplicitPackTypes = false; return result; } diff --git a/lib/AST/ASTPrinter.cpp b/lib/AST/ASTPrinter.cpp index bff08aa14dd7c..47f1720a9be45 100644 --- a/lib/AST/ASTPrinter.cpp +++ b/lib/AST/ASTPrinter.cpp @@ -6051,7 +6051,8 @@ class TypePrinter : public TypeVisitor { } void visitPackType(PackType *T) { - Printer << "Pack{"; + if (Options.PrintExplicitPackTypes) + Printer << "Pack{"; auto Fields = T->getElementTypes(); for (unsigned i = 0, e = Fields.size(); i != e; ++i) { @@ -6060,7 +6061,9 @@ class TypePrinter : public TypeVisitor { Type EltType = Fields[i]; visit(EltType); } - Printer << "}"; + + if (Options.PrintExplicitPackTypes) + Printer << "}"; } void visitSILPackType(SILPackType *T) { diff --git a/lib/Sema/CSDiagnostics.cpp b/lib/Sema/CSDiagnostics.cpp index 196217cb62aac..3ddfb17cd12e0 100644 --- a/lib/Sema/CSDiagnostics.cpp +++ b/lib/Sema/CSDiagnostics.cpp @@ -120,14 +120,6 @@ Type FailureDiagnostic::resolveType(Type rawType, bool reconstituteSugar, return env->mapElementTypeIntoPackContext(type); } - if (auto *packType = type->getAs()) { - if (packType->getNumElements() == 1) { - auto eltType = resolveType(packType->getElementType(0)); - if (auto expansion = eltType->getAs()) - return expansion->getPatternType(); - } - } - return type->isPlaceholder() ? Type(type->getASTContext().TheUnresolvedType) : type; }); diff --git a/lib/Sema/TypeCheckGeneric.cpp b/lib/Sema/TypeCheckGeneric.cpp index 899d8b017ea0b..6f9a595f0a5d4 100644 --- a/lib/Sema/TypeCheckGeneric.cpp +++ b/lib/Sema/TypeCheckGeneric.cpp @@ -839,6 +839,7 @@ static std::string gatherGenericParamBindingsText( SmallString<128> result; llvm::raw_svector_ostream OS(result); + auto options = PrintOptions::forDiagnosticArguments(); for (auto gp : genericParams) { auto canonGP = gp->getCanonicalType()->castTo(); @@ -860,19 +861,7 @@ static std::string gatherGenericParamBindingsText( if (!type) return ""; - if (auto *packType = type->getAs()) { - bool first = true; - for (auto eltType : packType->getElementTypes()) { - if (first) - first = false; - else - OS << ", "; - - OS << eltType; - } - } else { - OS << type.getString(); - } + type->print(OS, options); } OS << "]"; diff --git a/test/Constraints/pack-expansion-expressions.swift b/test/Constraints/pack-expansion-expressions.swift index a718ed2944acd..8c09b8e167ca5 100644 --- a/test/Constraints/pack-expansion-expressions.swift +++ b/test/Constraints/pack-expansion-expressions.swift @@ -138,7 +138,7 @@ func tupleExpansion( _ = zip(repeat each tuple1, with: repeat each tuple1.element) // legacy syntax _ = zip(repeat each tuple1, with: repeat each tuple2) - // expected-error@-1 {{global function 'zip(_:with:)' requires the type packs 'each T' and 'each U' have the same shape}} + // expected-error@-1 {{global function 'zip(_:with:)' requires the type packs 'repeat each T' and 'repeat each U' have the same shape}} _ = forward(repeat each tuple3) } diff --git a/test/Constraints/pack_expansion_types.swift b/test/Constraints/pack_expansion_types.swift index 1ac71c1421acb..92472e78cda16 100644 --- a/test/Constraints/pack_expansion_types.swift +++ b/test/Constraints/pack_expansion_types.swift @@ -240,9 +240,9 @@ func patternInstantiationConcreteValid() { func patternInstantiationConcreteInvalid() { let _: Set = patternInstantiationTupleTest1() - // expected-error@-1 {{cannot convert value of type '(repeat Array)' to specified type 'Set'}} + // expected-error@-1 {{cannot convert value of type '(repeat Array<_>)' to specified type 'Set'}} - let _: (Array, Set) = patternInstantiationTupleTest1() // expected-error {{'(repeat Array)' is not convertible to '(Array, Set)', tuples have a different number of elements}} + let _: (Array, Set) = patternInstantiationTupleTest1() // expected-error {{'(repeat Array)' is not convertible to '(Array, Set)', tuples have a different number of elements}} } func patternInstantiationGenericValid(t: repeat each T, u: repeat each U) @@ -272,7 +272,7 @@ func patternInstantiationGenericInvalid(t: repeat each T) { let _: (repeat Set) = patternInstantiationTupleTest1() // expected-error {{cannot convert value of type '(repeat Array)' to specified type '(repeat Set)}} // expected-error@-1 {{generic parameter 'each T' could not be inferred}} - let _: (repeat Array, Set) = patternInstantiationTupleTest1() // expected-error {{'(repeat Array)' is not convertible to '(repeat Array, Set)', tuples have a different number of elements}} + let _: (repeat Array, Set) = patternInstantiationTupleTest1() // expected-error {{'(repeat Array)' is not convertible to '(repeat Array, Set)', tuples have a different number of elements}} } // rdar://107996926 - Vanishing metatype of tuple not supported diff --git a/test/Constraints/variadic_generic_constraints.swift b/test/Constraints/variadic_generic_constraints.swift index 1748a4d9058b1..ce3d26786365c 100644 --- a/test/Constraints/variadic_generic_constraints.swift +++ b/test/Constraints/variadic_generic_constraints.swift @@ -65,7 +65,7 @@ let _ = zip(t: 1, u: "hi") // ok let _ = zip(t: 1, 2, u: "hi", "hello") // ok let _ = zip(t: 1, 2, 3, u: "hi", "hello", "greetings") // ok let _ = zip(t: 1, u: "hi", "hello", "greetings") // expected-error {{extra arguments at positions #3, #4 in call}} -// expected-error@-1 {{global function 'zip(t:u:)' requires the type packs 'Pack{Int}' and 'Pack{String, String, String}' have the same shape}} +// expected-error@-1 {{global function 'zip(t:u:)' requires the type packs 'Int' and 'String, String, String' have the same shape}} func goodCallToZip(t: repeat each T, u: repeat each U) where (repeat (each T, each U)): Any { _ = zip(t: repeat each t, u: repeat each u) @@ -73,5 +73,5 @@ func goodCallToZip(t: repeat each T, u: repeat each U) where (re func badCallToZip(t: repeat each T, u: repeat each U) { _ = zip(t: repeat each t, u: repeat each u) - // expected-error@-1 {{global function 'zip(t:u:)' requires the type packs 'each T' and 'each U' have the same shape}} + // expected-error@-1 {{global function 'zip(t:u:)' requires the type packs 'repeat each T' and 'repeat each U' have the same shape}} } diff --git a/test/Constraints/variadic_generic_types.swift b/test/Constraints/variadic_generic_types.swift index 2812198e7c0c2..8ff200b253297 100644 --- a/test/Constraints/variadic_generic_types.swift +++ b/test/Constraints/variadic_generic_types.swift @@ -22,3 +22,10 @@ func g(_: repeat each T) { // expected-error@-1 {{pack expansion 'Int' must contain at least one pack reference}} // expected-error@-2 {{'each' cannot be applied to non-pack type 'Int'}}{{15-19=}} } + +struct MissingMemberError { + init() { + self.doesNotExist = 1 + // expected-error@-1 {{value of type 'MissingMemberError' has no member 'doesNotExist'}} + } +} diff --git a/test/Generics/variadic_generic_requirements.swift b/test/Generics/variadic_generic_requirements.swift index dbf18ea6da67b..6be7b41be8fd3 100644 --- a/test/Generics/variadic_generic_requirements.swift +++ b/test/Generics/variadic_generic_requirements.swift @@ -30,8 +30,8 @@ struct Outer { } _ = Outer, Array>.Inner, Set>.self // ok -_ = Outer, Array>.Inner, Set>.self // expected-error {{'Outer, Array>.Inner' requires the types 'Pack{Int, String}' and 'Pack{String, Int}' be equivalent}} -_ = Outer>.Inner, Set>.self // expected-error {{'Outer>.Inner' requires the types 'Pack{Int}' and 'Pack{Int, String}' be equivalent}} +_ = Outer, Array>.Inner, Set>.self // expected-error {{'Outer, Array>.Inner' requires the types 'Int, String' and 'String, Int' be equivalent}} +_ = Outer>.Inner, Set>.self // expected-error {{'Outer>.Inner' requires the types 'Int' and 'Int, String' be equivalent}} _ = Outer, Array>.InnerShape, Set>.self // ok -_ = Outer>.InnerShape, Set>.self // expected-error {{'Outer>.InnerShape' requires the type packs 'Pack{Array}' and 'Pack{Set, Set}' have the same shape}} +_ = Outer>.InnerShape, Set>.self // expected-error {{'Outer>.InnerShape' requires the type packs 'Array' and 'Set, Set' have the same shape}}