diff --git a/CHANGELOG.md b/CHANGELOG.md index 2342db9ee2c6d..af00248802e1e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,26 @@ CHANGELOG Swift 3.1 --------- +* [SR-1446](https://bugs.swift.org/browse/SR-1446) + + Nested types may now appear inside generic types, and nested types may have their own generic parameters: + + ```swift + struct OuterNonGeneric { + struct InnerGeneric {} + } + + struct OuterGeneric { + struct InnerNonGeneric {} + + struct InnerGeneric {} + } + + extension OuterNonGeneric.InnerGeneric {} + extension OuterGeneric.InnerNonGeneric {} + extension OuterGeneric.InnerGeneric {} + ``` + * [SR-1009](https://bugs.swift.org/browse/SR-1009): Constrained extensions allow same-type constraints between generic parameters and concrete types. This enables you to create extensions, for example, on `Array` with `Int` elements: diff --git a/include/swift/AST/DiagnosticsSema.def b/include/swift/AST/DiagnosticsSema.def index 86bb4c4dd9842..dc9cbefb37aa7 100644 --- a/include/swift/AST/DiagnosticsSema.def +++ b/include/swift/AST/DiagnosticsSema.def @@ -1144,15 +1144,6 @@ ERROR(pattern_binds_no_variables,none, // Generic types -ERROR(unsupported_generic_nested_in_type,none, - "generic type %0 cannot be nested in type %1", - (Identifier, Identifier)) -ERROR(unsupported_type_nested_in_generic_type,none, - "type %0 cannot be nested in generic type %1", - (Identifier, Identifier)) -ERROR(unsupported_type_nested_in_generic_extension,none, - "type %0 cannot be nested in extension of generic type %1", - (Identifier, Identifier)) ERROR(unsupported_type_nested_in_generic_function,none, "type %0 cannot be nested in generic function %1", (Identifier, Identifier)) diff --git a/include/swift/Basic/LangOptions.h b/include/swift/Basic/LangOptions.h index 60fecd20142ec..98a41f1ee8908 100644 --- a/include/swift/Basic/LangOptions.h +++ b/include/swift/Basic/LangOptions.h @@ -141,9 +141,6 @@ namespace swift { /// \brief Enable experimental property behavior feature. bool EnableExperimentalPropertyBehaviors = false; - /// \brief Enable experimental nested generic types feature. - bool EnableExperimentalNestedGenericTypes = false; - /// \brief Staging flag for class resilience, which we do not want to enable /// fully until more code is in place, to allow the standard library to be /// tested with value type resilience only. diff --git a/include/swift/Option/FrontendOptions.td b/include/swift/Option/FrontendOptions.td index efc96a5d567a2..3caa27e828316 100644 --- a/include/swift/Option/FrontendOptions.td +++ b/include/swift/Option/FrontendOptions.td @@ -240,10 +240,6 @@ def enable_experimental_property_behaviors : Flag<["-"], "enable-experimental-property-behaviors">, HelpText<"Enable experimental property behaviors">; -def enable_experimental_nested_generic_types : - Flag<["-"], "enable-experimental-nested-generic-types">, - HelpText<"Enable experimental support for nested generic types">; - def disable_availability_checking : Flag<["-"], "disable-availability-checking">, HelpText<"Disable checking for potentially unavailable APIs">; diff --git a/lib/Basic/Demangle.cpp b/lib/Basic/Demangle.cpp index d196d239203e6..c38ae00d3560f 100644 --- a/lib/Basic/Demangle.cpp +++ b/lib/Basic/Demangle.cpp @@ -2396,6 +2396,11 @@ class NodePrinter { case Node::Kind::VariadicTuple: return true; + case Node::Kind::ProtocolList: + if (pointer->getChild(0)->getNumChildren() <= 1) + return true; + return false; + case Node::Kind::Allocator: case Node::Kind::ArgumentTuple: case Node::Kind::AssociatedTypeMetadataAccessor: @@ -2473,7 +2478,6 @@ class NodePrinter { case Node::Kind::PrefixOperator: case Node::Kind::ProtocolConformance: case Node::Kind::ProtocolDescriptor: - case Node::Kind::ProtocolList: case Node::Kind::ProtocolWitness: case Node::Kind::ProtocolWitnessTable: case Node::Kind::ProtocolWitnessTableAccessor: @@ -2686,8 +2690,6 @@ class NodePrinter { } // end anonymous namespace static bool isExistentialType(NodePointer node) { - assert(node->getKind() == Node::Kind::Type); - node = node->getChild(0); return (node->getKind() == Node::Kind::ExistentialMetatype || node->getKind() == Node::Kind::ProtocolList); } @@ -3004,7 +3006,10 @@ void NodePrinter::print(NodePointer pointer, bool asContext, bool suppressType) if (!pointer->hasChildren()) need_parens = true; else { - Node::Kind child0_kind = pointer->getChild(0)->getChild(0)->getKind(); + Node::Kind child0_kind = pointer->getChild(0)->getKind(); + if (child0_kind == Node::Kind::Type) + child0_kind = pointer->getChild(0)->getChild(0)->getKind(); + if (child0_kind != Node::Kind::VariadicTuple && child0_kind != Node::Kind::NonVariadicTuple) need_parens = true; @@ -3410,8 +3415,13 @@ void NodePrinter::print(NodePointer pointer, bool asContext, bool suppressType) Printer << " "; Idx++; } - NodePointer type = pointer->getChild(Idx); + NodePointer type = pointer->getChild(Idx)->getChild(0); + bool needs_parens = !isSimpleType(type); + if (needs_parens) + Printer << "("; print(type); + if (needs_parens) + Printer << ")"; if (isExistentialType(type)) { Printer << ".Protocol"; } else { diff --git a/lib/Frontend/CompilerInvocation.cpp b/lib/Frontend/CompilerInvocation.cpp index 15d98740bdefe..3d76237100159 100644 --- a/lib/Frontend/CompilerInvocation.cpp +++ b/lib/Frontend/CompilerInvocation.cpp @@ -804,9 +804,6 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args, Opts.EnableExperimentalPropertyBehaviors |= Args.hasArg(OPT_enable_experimental_property_behaviors); - Opts.EnableExperimentalNestedGenericTypes |= - Args.hasArg(OPT_enable_experimental_nested_generic_types); - Opts.EnableClassResilience |= Args.hasArg(OPT_enable_class_resilience); diff --git a/lib/Sema/TypeCheckDecl.cpp b/lib/Sema/TypeCheckDecl.cpp index 2efa49ad39c2e..75387016e6f42 100644 --- a/lib/Sema/TypeCheckDecl.cpp +++ b/lib/Sema/TypeCheckDecl.cpp @@ -3969,33 +3969,6 @@ class DeclChecker : public DeclVisitor { return true; } - if (!TC.Context.LangOpts.EnableExperimentalNestedGenericTypes) { - if (auto parent = dyn_cast(DC)) { - if (NTD->getGenericParams()) - TC.diagnose(NTD->getLoc(), diag::unsupported_generic_nested_in_type, - NTD->getName(), - parent->getName()); - else - TC.diagnose(NTD->getLoc(), - diag::unsupported_type_nested_in_generic_type, - NTD->getName(), - parent->getName()); - NTD->setInvalid(); - return true; - } else if (auto ED = dyn_cast(DC)) { - auto *parent = ED->getAsNominalTypeOrNominalTypeExtensionContext(); - if (parent == nullptr) { - /* Invalid extension -- diagnosed elsewhere */ - return true; - } - - TC.diagnose(NTD->getLoc(), - diag::unsupported_type_nested_in_generic_extension, - NTD->getName(), - parent->getName()); - } - } - if (DC->isLocalContext() && DC->isGenericContext()) { // A local generic context is a generic function. if (auto AFD = dyn_cast(DC)) { diff --git a/stdlib/public/core/HashedCollections.swift.gyb b/stdlib/public/core/HashedCollections.swift.gyb index e31f39ec6862f..de50a834c6d04 100644 --- a/stdlib/public/core/HashedCollections.swift.gyb +++ b/stdlib/public/core/HashedCollections.swift.gyb @@ -451,9 +451,6 @@ public struct Set : internal typealias _VariantBuffer = _VariantSetBuffer internal typealias _NativeBuffer = _NativeSetBuffer - /// The index type for subscripting the set. - public typealias Index = SetIndex - internal var _variantBuffer: _VariantBuffer /// Creates a new, empty set with at least the specified number of elements' @@ -1642,9 +1639,6 @@ public struct Dictionary : /// key-value pair. public typealias Element = (key: Key, value: Value) - /// The index type of a dictionary. - public typealias Index = DictionaryIndex - internal var _variantBuffer: _VariantBuffer /// Creates an empty dictionary. @@ -4705,6 +4699,7 @@ internal enum ${Self}IndexRepresentation<${TypeParametersDecl}> { case _cocoa(_CocoaIndex) } +extension ${Self} { %{ if Self == 'Set': SubscriptingWithIndexDoc = """\ @@ -4726,12 +4721,7 @@ elif Self == 'Dictionary': }% ${SubscriptingWithIndexDoc} -public struct ${Self}Index<${TypeParametersDecl}> : - Comparable { - // FIXME(ABI)#34 (Nesting types in generics): `DictionaryIndex` and `SetIndex` should - // be nested types (Dictionary.Index and Set.Index). - // rdar://problem/17002096 - +public struct Index : Comparable { // Index for native buffer is efficient. Index for bridged NS${Self} is // not, because neither NSEnumerator nor fast enumeration support moving // backwards. Even if they did, there is another issue: NSEnumerator does @@ -4750,12 +4740,12 @@ public struct ${Self}Index<${TypeParametersDecl}> : internal var _value: ${Self}IndexRepresentation<${TypeParameters}> @_versioned - internal static func _native(_ index: _NativeIndex) -> ${Self}Index { + internal static func _native(_ index: _NativeIndex) -> Index { return ${Self}Index(_value: ._native(index)) } #if _runtime(_ObjC) @_versioned - internal static func _cocoa(_ index: _CocoaIndex) -> ${Self}Index { + internal static func _cocoa(_ index: _CocoaIndex) -> Index { return ${Self}Index(_value: ._cocoa(index)) } #endif @@ -4789,10 +4779,15 @@ public struct ${Self}Index<${TypeParametersDecl}> : #endif } -extension ${Self}Index { +} + +public typealias ${Self}Index<${TypeParametersDecl}> = + ${Self}<${TypeParameters}>.Index + +extension ${Self}.Index { public static func == ( - lhs: ${Self}Index<${TypeParameters}>, - rhs: ${Self}Index<${TypeParameters}> + lhs: ${Self}<${TypeParameters}>.Index, + rhs: ${Self}<${TypeParameters}>.Index ) -> Bool { if _fastPath(lhs._guaranteedNative) { return lhs._nativeIndex == rhs._nativeIndex @@ -4813,8 +4808,8 @@ extension ${Self}Index { } public static func < ( - lhs: ${Self}Index<${TypeParameters}>, - rhs: ${Self}Index<${TypeParameters}> + lhs: ${Self}<${TypeParameters}>.Index, + rhs: ${Self}<${TypeParameters}>.Index ) -> Bool { if _fastPath(lhs._guaranteedNative) { return lhs._nativeIndex < rhs._nativeIndex diff --git a/stdlib/public/runtime/Casting.cpp b/stdlib/public/runtime/Casting.cpp index 2082032a2dd9c..5f916fa92abb3 100644 --- a/stdlib/public/runtime/Casting.cpp +++ b/stdlib/public/runtime/Casting.cpp @@ -63,136 +63,11 @@ extern "C" const void *swift_dynamicCastObjCProtocolConditional( const ProtocolDescriptor * const *protocols); #endif -namespace { - enum class TypeSyntaxLevel { - /// Any type syntax is valid. - Type, - /// Function types must be parenthesized. - TypeSimple, - }; -} - -static void _buildNameForMetadata(const Metadata *type, - TypeSyntaxLevel level, - bool qualified, - std::string &result); - -static void _buildNominalTypeName(const NominalTypeDescriptor *ntd, - const Metadata *type, - bool qualified, - std::string &result) { - auto options = Demangle::DemangleOptions(); - options.DisplayDebuggerGeneratedModule = false; - options.QualifyEntities = qualified; - - // Demangle the basic type name. - result += Demangle::demangleTypeAsString(ntd->Name, - strlen(ntd->Name), - options); - - // If generic, demangle the type parameters. - if (ntd->GenericParams.NumPrimaryParams > 0) { - result += "<"; - - auto typeBytes = reinterpret_cast(type); - auto genericParam = reinterpret_cast( - typeBytes + sizeof(void*) * ntd->GenericParams.Offset); - for (unsigned i = 0, e = ntd->GenericParams.NumPrimaryParams; - i < e; ++i, ++genericParam) { - if (i > 0) - result += ", "; - _buildNameForMetadata(*genericParam, TypeSyntaxLevel::Type, qualified, - result); - } - - result += ">"; - } -} - -static const char *_getProtocolName(const ProtocolDescriptor *protocol) { - const char *name = protocol->Name; - - // An Objective-C protocol's name is unmangled. -#if SWIFT_OBJC_INTEROP - if (!protocol->Flags.isSwift()) - return name; -#endif - - // Protocol names are emitted with the _Tt prefix so that ObjC can - // recognize them as mangled Swift names. - assert(name[0] == '_' && name[1] == 'T' && name[2] == 't'); - return name + 3; -} - -static void _buildExistentialTypeName(const ProtocolDescriptorList *protocols, - TypeSyntaxLevel level, - bool qualified, - std::string &result) { - auto options = Demangle::DemangleOptions(); - options.QualifyEntities = qualified; - options.DisplayDebuggerGeneratedModule = false; - - // If there's only one protocol, the existential type name is the protocol - // name. If there are 0 protocols it is 'Any' - auto descriptors = protocols->getProtocols(); - auto numProtocols = protocols->NumProtocols; - - if (numProtocols == 0) { - result += "Any"; - } else { - // compositions of more than 1 protocol need parens in .Type contexts - bool needsParens = (level >= TypeSyntaxLevel::TypeSimple) && (numProtocols != 1); - if (needsParens) result += "("; - for (unsigned i = 0, e = numProtocols; i < e; ++i) { - if (i) result += " & "; - auto name = _getProtocolName(descriptors[i]); - result += Demangle::demangleTypeAsString(name, - strlen(name), - options); - } - if (needsParens) result += ")"; - } -} - -static void _buildFunctionTypeName(const FunctionTypeMetadata *func, - bool qualified, - std::string &result) { - - result += "("; - for (size_t i = 0; i < func->getNumArguments(); ++i) { - auto arg = func->getArguments()[i].getPointer(); - bool isInout = func->getArguments()[i].getFlag(); - if (isInout) - result += "inout "; - _buildNameForMetadata(arg, TypeSyntaxLevel::TypeSimple, - qualified, result); - if (i < func->getNumArguments() - 1) { - result += ", "; - } - } - result += ")"; - - if (func->throws()) { - result += " throws"; - } - - result += " -> "; - _buildNameForMetadata(func->ResultType, - TypeSyntaxLevel::Type, - qualified, - result); -} - // Build a user-comprehensible name for a type. static void _buildNameForMetadata(const Metadata *type, - TypeSyntaxLevel level, bool qualified, std::string &result) { - auto options = Demangle::DemangleOptions(); - options.DisplayDebuggerGeneratedModule = false; - - switch (type->getKind()) { - case MetadataKind::Class: { + if (type->getKind() == MetadataKind::Class) { auto classType = static_cast(type); #if SWIFT_OBJC_INTEROP // Look through artificial subclasses. @@ -205,130 +80,32 @@ static void _buildNameForMetadata(const Metadata *type, return; } #endif - return _buildNominalTypeName(classType->getDescription(), - classType, qualified, - result); - } - case MetadataKind::Enum: - case MetadataKind::Optional: - case MetadataKind::Struct: { - auto structType = static_cast(type); - return _buildNominalTypeName(structType->Description, - type, qualified, result); - } - case MetadataKind::ObjCClassWrapper: { + } else if (type->getKind() == MetadataKind::ObjCClassWrapper) { #if SWIFT_OBJC_INTEROP auto objcWrapper = static_cast(type); - result += class_getName(objcWrapper->Class); -#else - assert(false && "no ObjC interop"); -#endif - return; - } - case MetadataKind::ForeignClass: { - auto foreign = static_cast(type); - const char *name = foreign->getName(); - size_t len = strlen(name); - result += Demangle::demangleTypeAsString(name, len, options); - return; - } - case MetadataKind::Existential: { - auto exis = static_cast(type); - _buildExistentialTypeName(&exis->Protocols, level, qualified, result); - return; - } - case MetadataKind::ExistentialMetatype: { - auto metatype = static_cast(type); - _buildNameForMetadata(metatype->InstanceType, TypeSyntaxLevel::TypeSimple, - qualified, - result); - result += ".Type"; + const char *className = class_getName((Class)objcWrapper->Class); + result = className; return; +#endif } - case MetadataKind::Function: { - if (level >= TypeSyntaxLevel::TypeSimple) - result += "("; - - auto func = static_cast(type); - - switch (func->getConvention()) { - case FunctionMetadataConvention::Swift: - break; - case FunctionMetadataConvention::Thin: - result += "@convention(thin) "; - break; - case FunctionMetadataConvention::Block: - result += "@convention(block) "; - break; - case FunctionMetadataConvention::CFunctionPointer: - result += "@convention(c) "; - break; - } - - _buildFunctionTypeName(func, qualified, result); - if (level >= TypeSyntaxLevel::TypeSimple) - result += ")"; + // Use the remangler to generate a mangled name from the type metadata. + auto demangling = _swift_buildDemanglingForMetadata(type); + if (demangling == nullptr) { + result = "<<< invalid type >>>"; return; } - case MetadataKind::Metatype: { - auto metatype = static_cast(type); - _buildNameForMetadata(metatype->InstanceType, TypeSyntaxLevel::TypeSimple, - qualified, result); - if (metatype->InstanceType->isAnyExistentialType()) - result += ".Protocol"; - else - result += ".Type"; - return; - } - case MetadataKind::Tuple: { - auto tuple = static_cast(type); - result += "("; - auto elts = tuple->getElements(); - const char *labels = tuple->Labels; - for (unsigned i = 0, e = tuple->NumElements; i < e; ++i) { - if (i > 0) - result += ", "; - - // If we have any labels, add the label. - if (labels) { - // Labels are space-separated. - if (const char *space = strchr(labels, ' ')) { - if (labels != space) { - result.append(labels, space - labels); - result += ": "; - } - - labels = space + 1; - } else { - labels = nullptr; - } - } - _buildNameForMetadata(elts[i].Type, TypeSyntaxLevel::Type, qualified, - result); - } - result += ")"; - return; - } - case MetadataKind::Opaque: { - // TODO - result += "<<>>"; - return; - } - case MetadataKind::HeapLocalVariable: - case MetadataKind::HeapGenericLocalVariable: - case MetadataKind::ErrorObject: - break; - } - result += "<<>>"; + Demangle::DemangleOptions options; + options.QualifyEntities = qualified; + result = Demangle::nodeToString(demangling, options); } /// Return a user-comprehensible name for the given type. std::string swift::nameForMetadata(const Metadata *type, bool qualified) { std::string result; - _buildNameForMetadata(type, TypeSyntaxLevel::Type, qualified, result); + _buildNameForMetadata(type, qualified, result); return result; } diff --git a/stdlib/public/runtime/Demangle.cpp b/stdlib/public/runtime/Demangle.cpp index 14c5667fec2e3..7f9cdedd6f27e 100644 --- a/stdlib/public/runtime/Demangle.cpp +++ b/stdlib/public/runtime/Demangle.cpp @@ -4,19 +4,74 @@ #include "Private.h" #if SWIFT_OBJC_INTEROP - #include +#endif + +// FIXME: This stuff should be merged with the existing logic in +// include/swift/Reflection/TypeRefBuilder.h as part of the rewrite +// to change stdlib reflection over to using remote mirrors. + +Demangle::NodePointer +swift::_swift_buildDemanglingForMetadata(const Metadata *type); // Build a demangled type tree for a nominal type. static Demangle::NodePointer -_buildDemanglingForNominalType(Demangle::Node::Kind boundGenericKind, - const Metadata *type, - const NominalTypeDescriptor *description) { +_buildDemanglingForNominalType(const Metadata *type) { using namespace Demangle; - + + const Metadata *parent; + Node::Kind boundGenericKind; + const NominalTypeDescriptor *description; + + // Demangle the parent type, if any. + switch (type->getKind()) { + case MetadataKind::Class: { + auto classType = static_cast(type); + parent = classType->getParentType(classType->getDescription()); + boundGenericKind = Node::Kind::BoundGenericClass; + description = classType->getDescription(); + break; + } + case MetadataKind::Enum: + case MetadataKind::Optional: { + auto enumType = static_cast(type); + parent = enumType->Parent; + boundGenericKind = Node::Kind::BoundGenericEnum; + description = enumType->Description; + break; + } + case MetadataKind::Struct: { + auto structType = static_cast(type); + parent = structType->Parent; + boundGenericKind = Node::Kind::BoundGenericStructure; + description = structType->Description; + break; + } + default: + return nullptr; + } + // Demangle the base name. auto node = demangleTypeAsNode(description->Name, - strlen(description->Name)); + strlen(description->Name)); + assert(node->getKind() == Node::Kind::Type); + + // Demangle the parent. + if (parent) { + auto parentNode = _swift_buildDemanglingForMetadata(parent); + if (parentNode->getKind() == Node::Kind::Type) + parentNode = parentNode->getChild(0); + + auto typeNode = node->getChild(0); + auto newTypeNode = NodeFactory::create(typeNode->getKind()); + newTypeNode->addChild(parentNode); + newTypeNode->addChild(typeNode->getChild(1)); + + auto newNode = NodeFactory::create(Node::Kind::Type); + newNode->addChild(newTypeNode); + node = newNode; + } + // If generic, demangle the type parameters. if (description->GenericParams.NumPrimaryParams > 0) { auto typeParams = NodeFactory::create(Node::Kind::TypeList); @@ -44,22 +99,11 @@ Demangle::NodePointer swift::_swift_buildDemanglingForMetadata(const Metadata *t using namespace Demangle; switch (type->getKind()) { - case MetadataKind::Class: { - auto classType = static_cast(type); - return _buildDemanglingForNominalType(Node::Kind::BoundGenericClass, - type, classType->getDescription()); - } + case MetadataKind::Class: case MetadataKind::Enum: - case MetadataKind::Optional: { - auto structType = static_cast(type); - return _buildDemanglingForNominalType(Node::Kind::BoundGenericEnum, - type, structType->Description); - } - case MetadataKind::Struct: { - auto structType = static_cast(type); - return _buildDemanglingForNominalType(Node::Kind::BoundGenericStructure, - type, structType->Description); - } + case MetadataKind::Optional: + case MetadataKind::Struct: + return _buildDemanglingForNominalType(type); case MetadataKind::ObjCClassWrapper: { #if SWIFT_OBJC_INTEROP auto objcWrapper = static_cast(type); @@ -203,8 +247,10 @@ Demangle::NodePointer swift::_swift_buildDemanglingForMetadata(const Metadata *t case MetadataKind::Metatype: { auto metatype = static_cast(type); auto instance = _swift_buildDemanglingForMetadata(metatype->InstanceType); + auto typeNode = NodeFactory::create(Node::Kind::Type); + typeNode->addChild(instance); auto node = NodeFactory::create(Node::Kind::Metatype); - node->addChild(instance); + node->addChild(typeNode); return node; } case MetadataKind::Tuple: { @@ -252,5 +298,3 @@ Demangle::NodePointer swift::_swift_buildDemanglingForMetadata(const Metadata *t // Not a type. return nullptr; } - -#endif diff --git a/stdlib/public/runtime/Private.h b/stdlib/public/runtime/Private.h index c3b09f2add9e2..59c5fb762c6ad 100644 --- a/stdlib/public/runtime/Private.h +++ b/stdlib/public/runtime/Private.h @@ -156,9 +156,7 @@ namespace swift { const Metadata * _searchConformancesByMangledTypeName(const llvm::StringRef typeName); -#if SWIFT_OBJC_INTEROP Demangle::NodePointer _swift_buildDemanglingForMetadata(const Metadata *type); -#endif /// A helper function which avoids performing a store if the destination /// address already contains the source value. This is useful when diff --git a/test/Constraints/members.swift b/test/Constraints/members.swift index 0db3ffdca6177..2580dacf30908 100644 --- a/test/Constraints/members.swift +++ b/test/Constraints/members.swift @@ -131,7 +131,7 @@ func enumMetatypeMember(_ opt: Int?) { // Reference a Type member. class G { - class In { // expected-error{{nested in generic type}} + class In { class func foo() {} } } diff --git a/test/Generics/invalid.swift b/test/Generics/invalid.swift index 2d62e3b3bc0a0..d0126517f0e0e 100644 --- a/test/Generics/invalid.swift +++ b/test/Generics/invalid.swift @@ -1,4 +1,4 @@ -// RUN: %target-parse-verify-swift -enable-experimental-nested-generic-types +// RUN: %target-parse-verify-swift func bet() where A : B {} // expected-error {{'where' clause cannot be attached to a non-generic declaration}} diff --git a/test/Generics/unbound.swift b/test/Generics/unbound.swift index a95863469647d..df7d795bae0d1 100644 --- a/test/Generics/unbound.swift +++ b/test/Generics/unbound.swift @@ -9,7 +9,7 @@ // -------------------------------------------------- struct Foo { // expected-note{{generic type 'Foo' declared here}} expected-note{{generic type 'Foo' declared here}} - struct Wibble { } // expected-error{{cannot be nested in generic type}} + struct Wibble { } } class Dict { } // expected-note{{generic type 'Dict' declared here}} expected-note{{generic type 'Dict' declared here}} expected-note{{generic type 'Dict' declared here}} diff --git a/test/IDE/print_stdlib.swift b/test/IDE/print_stdlib.swift index b864e8896960c..36d4bdeb1da02 100644 --- a/test/IDE/print_stdlib.swift +++ b/test/IDE/print_stdlib.swift @@ -37,7 +37,6 @@ // CHECK-NOT: func ~> // CHECK-NOT: _builtin // CHECK-NOT: Builtin. -// CHECK-NOT: extension [ // CHECK-NOT: extension {{.*}}? // CHECK-NOT: extension {{.*}}! // CHECK-NOT: addressWithOwner diff --git a/test/Interpreter/nested_generics.swift b/test/Interpreter/nested_generics.swift index 8156f33e29979..4c0f0e71fa3a8 100644 --- a/test/Interpreter/nested_generics.swift +++ b/test/Interpreter/nested_generics.swift @@ -1,5 +1,5 @@ // RUN: mkdir -p %t -// RUN: %target-build-swift %s -Xfrontend -enable-experimental-nested-generic-types -o %t/a.out +// RUN: %target-build-swift %s -o %t/a.out // RUN: %target-run %t/a.out | %FileCheck %s // REQUIRES: executable_test diff --git a/test/Interpreter/tuple_casts.swift b/test/Interpreter/tuple_casts.swift index 4c573a8dbaaef..e1f1d08877f50 100644 --- a/test/Interpreter/tuple_casts.swift +++ b/test/Interpreter/tuple_casts.swift @@ -47,7 +47,7 @@ tupleCastTests.test("Incorrect labels conditional cast") { tupleCastTests .test("Incorrect labels forced cast") - .crashOutputMatches("Could not cast value of type '(x: Swift.Int, z: Swift.Int)'") + .crashOutputMatches("Could not cast value of type '(x : Swift.Int, z : Swift.Int)'") .code { expectCrashLater() _ = anyToIntPoint((x: 1, z: 2)) diff --git a/test/Interpreter/typeof.swift b/test/Interpreter/typeof.swift index bef828c9bba16..a88a9d907b0cc 100644 --- a/test/Interpreter/typeof.swift +++ b/test/Interpreter/typeof.swift @@ -85,5 +85,5 @@ print(boxedExistentialMetatype(Meltdown())) print(boxedExistentialMetatype(GrilledCheese())) // CHECK: GrilledCheese print(boxedExistentialMetatype(GrilledCheese() as Meltdown)) -// CHECK: (x: Int, y: Int, Double) +// CHECK: (x : Int, y : Int, Double) print(type(of: labeledTuple())) diff --git a/test/Parse/generic_disambiguation.swift b/test/Parse/generic_disambiguation.swift index 15ed1bebf8137..28b504ba30914 100644 --- a/test/Parse/generic_disambiguation.swift +++ b/test/Parse/generic_disambiguation.swift @@ -4,11 +4,11 @@ struct A { // expected-note{{generic type 'A' declared here}} init(x:Int) {} static func c() {} - struct C { // expected-error{{generic type 'C' cannot be nested in type 'A'}} + struct C { static func e() {} } - struct F {} // expected-error{{type 'F' cannot be nested in generic type 'A'}} + struct F {} } struct B {} struct D {} diff --git a/test/Parse/matching_patterns.swift b/test/Parse/matching_patterns.swift index e89f1063d2d19..634b323747cfe 100644 --- a/test/Parse/matching_patterns.swift +++ b/test/Parse/matching_patterns.swift @@ -13,7 +13,7 @@ var x:Int func square(_ x: Int) -> Int { return x*x } struct A { - struct C { } // expected-error{{generic type 'C' cannot be nested in type 'A'}} + struct C { } } switch x { @@ -143,7 +143,7 @@ case .Foo: // expected-error{{enum case 'Foo' not found in type 'Int'}} } struct ContainsEnum { - enum Possible { // expected-error{{generic type 'Possible' cannot be nested in type 'ContainsEnum'}} + enum Possible { case Naught case Mere(T) case Twain(T, T) @@ -151,7 +151,7 @@ struct ContainsEnum { func member(_ n: Possible) { switch n { - case ContainsEnum.Possible.Naught, // expected-error{{cannot specialize a non-generic definition}} expected-note {{while parsing this '<' as a type parameter bracket}} + case ContainsEnum.Possible.Naught, ContainsEnum.Possible.Naught, Possible.Naught, Possible.Naught, @@ -163,7 +163,7 @@ struct ContainsEnum { func nonmemberAccessesMemberType(_ n: ContainsEnum.Possible) { switch n { - case ContainsEnum.Possible.Naught, // expected-error{{cannot specialize a non-generic definition}} expected-note {{while parsing this '<' as a type parameter bracket}} + case ContainsEnum.Possible.Naught, .Naught: () } diff --git a/test/Parse/type_expr.swift b/test/Parse/type_expr.swift index b439465cbc698..d986ef9029674 100644 --- a/test/Parse/type_expr.swift +++ b/test/Parse/type_expr.swift @@ -31,7 +31,7 @@ protocol Bad { } struct Gen { - struct Bar { // expected-error{{nested in generic type}} + struct Bar { init() {} static var prop: Int { return 0 } static func meth() {} @@ -106,8 +106,11 @@ func genQualifiedType() { let _ : () = Gen.Bar.meth() _ = Gen.Bar.instMeth - _ = Gen.Bar - _ = Gen.Bar.dynamicType // expected-error {{'.dynamicType' is deprecated. Use 'type(of: ...)' instead}} {{7-7=type(of: }} {{19-31=)}} + _ = Gen.Bar // expected-error{{expected member name or constructor call after type name}} + // expected-note@-1{{add arguments after the type to construct a value of the type}} + // expected-note@-2{{use '.self' to reference the type object}} + _ = Gen.Bar.dynamicType // expected-error {{type 'Gen.Bar' has no member 'dynamicType'}} + // expected-error@-1 {{'.dynamicType' is deprecated. Use 'type(of: ...)' instead}} {{7-7=type(of: }} {{19-31=)}} } func typeOfShadowing() { @@ -128,8 +131,10 @@ func typeOfShadowing() { return t } - _ = type(of: Gen.Bar) // No error here. - _ = type(Gen.Bar) // No error here. + _ = type(of: Gen.Bar) // expected-error{{expected member name or constructor call after type name}} + // expected-note@-1{{add arguments after the type to construct a value of the type}} + // expected-note@-2{{use '.self' to reference the type object}} + _ = type(Gen.Bar) // expected-warning{{missing '.self' for reference to metatype of type 'Gen.Bar'}} _ = type(of: Gen.Bar.self, flag: false) // No error here. _ = type(fo: Foo.Bar.self) // No error here. _ = type(of: Foo.Bar.self, [1, 2, 3]) // No error here. diff --git a/test/SILGen/nested_generics.swift b/test/SILGen/nested_generics.swift index 1ff3f660c5f67..8afb15f7bc19c 100644 --- a/test/SILGen/nested_generics.swift +++ b/test/SILGen/nested_generics.swift @@ -1,7 +1,7 @@ -// RUN: %target-swift-frontend -Xllvm -sil-full-demangle -emit-silgen -enable-experimental-nested-generic-types -parse-as-library %s | %FileCheck %s -// RUN: %target-swift-frontend -Xllvm -sil-full-demangle -emit-sil -enable-experimental-nested-generic-types -parse-as-library %s > /dev/null -// RUN: %target-swift-frontend -Xllvm -sil-full-demangle -emit-sil -O -enable-experimental-nested-generic-types -parse-as-library %s > /dev/null -// RUN: %target-swift-frontend -Xllvm -sil-full-demangle -emit-ir -enable-experimental-nested-generic-types -parse-as-library %s > /dev/null +// RUN: %target-swift-frontend -Xllvm -sil-full-demangle -emit-silgen -parse-as-library %s | %FileCheck %s +// RUN: %target-swift-frontend -Xllvm -sil-full-demangle -emit-sil -parse-as-library %s > /dev/null +// RUN: %target-swift-frontend -Xllvm -sil-full-demangle -emit-sil -O -parse-as-library %s > /dev/null +// RUN: %target-swift-frontend -Xllvm -sil-full-demangle -emit-ir -parse-as-library %s > /dev/null // TODO: // - test generated SIL -- mostly we're just testing mangling here diff --git a/test/Sema/accessibility_private.swift b/test/Sema/accessibility_private.swift index 3925ae0944a94..6f2bc0ea5fa72 100644 --- a/test/Sema/accessibility_private.swift +++ b/test/Sema/accessibility_private.swift @@ -198,8 +198,7 @@ extension Container { private class PrivateInnerClass {} // expected-note * {{declared here}} fileprivate class PrivateSuperClass: PrivateInnerClass {} // expected-warning {{class should not be declared fileprivate because its superclass is private}} {{none}} fileprivate class PrivateGenericUser where T: PrivateInnerClass {} // expected-warning {{generic class should not be declared fileprivate because its generic requirement uses a private type}} {{none}} - // expected-error@-1 {{type 'PrivateGenericUser' cannot be nested in extension of generic type 'Container'}} - // FIXME expected-error@-2 {{cannot conform to class protocol 'AnyObject'}} + // FIXME expected-error@-1 {{cannot conform to class protocol 'AnyObject'}} } fileprivate struct SR2579 { diff --git a/test/api-digester/source-stability.swift.expected b/test/api-digester/source-stability.swift.expected index 0bcc36d79bfc8..4b545b87fbdce 100644 --- a/test/api-digester/source-stability.swift.expected +++ b/test/api-digester/source-stability.swift.expected @@ -1,3 +1,13 @@ +/* DictionaryIndex => Dictionary.Index, + * SetIndex => Set.Index + * + * Note: The old names are still available via generic typealiases, + * however swift-api-digester doesn't pick that up yet. */ +TypeAlias Dictionary.Index has been removed +TypeAlias Set.Index has been removed +Struct DictionaryIndex has been removed +Struct SetIndex has been removed + /* Removed declarations */ Protocol BidirectionalIndexable has been removed (deprecated) Protocol ExpressibleByStringInterpolation has been removed (deprecated) @@ -7,5 +17,18 @@ Protocol MutableIndexable has been removed (deprecated) Protocol RandomAccessIndexable has been removed (deprecated) Protocol RangeReplaceableIndexable has been removed (deprecated) +/* More DictionaryIndex / SetIndex */ +Var Dictionary.endIndex has declared type change from DictionaryIndex to Dictionary.Index +Var Dictionary.startIndex has declared type change from DictionaryIndex to Dictionary.Index +Var Set.endIndex has declared type change from SetIndex to Set.Index +Var Set.startIndex has declared type change from SetIndex to Set.Index +Func Dictionary.index(after:) has return type change from DictionaryIndex to Dictionary.Index +Func Dictionary.index(forKey:) has return type change from DictionaryIndex? to Dictionary.Index? +Func Dictionary.remove(at:) has 1st parameter type change from DictionaryIndex to Dictionary.Index +Func Set.index(after:) has return type change from SetIndex to Set.Index +Func Set.index(of:) has return type change from SetIndex? to Set.Index? +Func Set.remove(at:) has 1st parameter type change from SetIndex to Set.Index + /* Function type change */ Func UnsafePointer.withMemoryRebound(to:capacity:_:) has 3rd parameter type change from (UnsafeMutablePointer) throws -> Result to (UnsafePointer) throws -> Result + diff --git a/test/attr/attr_objc.swift b/test/attr/attr_objc.swift index aed78da0dd660..0a3f1afc0d44b 100644 --- a/test/attr/attr_objc.swift +++ b/test/attr/attr_objc.swift @@ -383,22 +383,22 @@ func genericContext1(_: T) { class GenericContext2 { @objc // expected-error{{generic subclasses of '@objc' classes cannot have an explicit '@objc' attribute because they are not directly visible from Objective-C}} {{3-9=}} - class subject_inGenericContext {} // expected-error{{nested in generic type}} + class subject_inGenericContext {} @objc // expected-error{{generic subclasses of '@objc' classes cannot have an explicit '@objc' attribute}} {{3-9=}} - class subject_inGenericContext2 : Class_ObjC1 {} // expected-error{{nested in generic type}} + class subject_inGenericContext2 : Class_ObjC1 {} @objc func f() {} // no-error } class GenericContext3 { - class MoreNested { // expected-error{{nested in generic type}} + class MoreNested { @objc // expected-error{{generic subclasses of '@objc' classes cannot have an explicit '@objc' attribute because they are not directly visible from Objective-C}} {{5-11=}} - class subject_inGenericContext {} // expected-error{{nested in generic type}} + class subject_inGenericContext {} @objc // expected-error{{generic subclasses of '@objc' classes cannot have an explicit '@objc' attribute}} {{5-11=}} - class subject_inGenericContext2 : Class_ObjC1 {} // expected-error{{nested in generic type}} + class subject_inGenericContext2 : Class_ObjC1 {} @objc func f() {} // no-error diff --git a/test/decl/ext/generic.swift b/test/decl/ext/generic.swift index 53fd94c3864cf..bcf5400415688 100644 --- a/test/decl/ext/generic.swift +++ b/test/decl/ext/generic.swift @@ -5,9 +5,9 @@ protocol P2 : P1 { } protocol P3 { } struct X { - struct Inner { } // expected-error{{generic type 'Inner' cannot be nested in type 'X'}} + struct Inner { } - struct NonGenericInner { } // expected-error{{nested in generic type}} + struct NonGenericInner { } } extension Int : P1 { diff --git a/test/decl/func/default-values.swift b/test/decl/func/default-values.swift index 53e8d8cf98a5d..a296706a872e6 100644 --- a/test/decl/func/default-values.swift +++ b/test/decl/func/default-values.swift @@ -40,17 +40,17 @@ Ctor(f:12.5) // expected-warning{{unused}} // Default arguments for nested constructors/functions. struct Outer { - struct Inner { // expected-error{{type 'Inner' cannot be nested in generic type 'Outer'}} - struct VeryInner {// expected-error{{type 'VeryInner' cannot be nested in generic type 'Inner'}} + struct Inner { + struct VeryInner { init (i : Int = 17, f : Float = 1.5) { } static func f(i: Int = 17, f: Float = 1.5) { } func g(i: Int = 17, f: Float = 1.5) { } } } } -Outer.Inner.VeryInner() -Outer.Inner.VeryInner(i: 12) -Outer.Inner.VeryInner(f:12.5) +_ = Outer.Inner.VeryInner() +_ = Outer.Inner.VeryInner(i: 12) +_ = Outer.Inner.VeryInner(f:12.5) Outer.Inner.VeryInner.f() Outer.Inner.VeryInner.f(i: 12) Outer.Inner.VeryInner.f(f:12.5) diff --git a/test/decl/nested/type_in_extension.swift b/test/decl/nested/type_in_extension.swift index 57d3f04f39a1e..5ef6c8ddf727a 100644 --- a/test/decl/nested/type_in_extension.swift +++ b/test/decl/nested/type_in_extension.swift @@ -3,7 +3,7 @@ struct G {} extension G { - struct H { } // expected-error {{type 'H' cannot be nested in extension of generic type 'G'}} + struct H { } } extension { // expected-error {{expected type name in extension declaration}} diff --git a/test/decl/nested/type_in_type.swift b/test/decl/nested/type_in_type.swift index 0e053799a45a7..cd67c8b4876c9 100644 --- a/test/decl/nested/type_in_type.swift +++ b/test/decl/nested/type_in_type.swift @@ -3,28 +3,28 @@ struct OuterNonGeneric { struct MidNonGeneric { struct InnerNonGeneric {} - struct InnerGeneric {} // expected-error{{generic type 'InnerGeneric' cannot be nested in type 'MidNonGeneric'}} + struct InnerGeneric {} } - struct MidGeneric { // expected-error{{generic type 'MidGeneric' cannot be nested in type 'OuterNonGeneric'}} - struct InnerNonGeneric {} // expected-error{{type 'InnerNonGeneric' cannot be nested in generic type 'MidGeneric'}} - struct InnerGeneric {} // expected-error{{generic type 'InnerGeneric' cannot be nested in type 'MidGeneric'}} + struct MidGeneric { + struct InnerNonGeneric {} + struct InnerGeneric {} func flock(_ b: B) {} } } struct OuterGeneric { - struct MidNonGeneric { // expected-error{{type 'MidNonGeneric' cannot be nested in generic type 'OuterGeneric'}} - struct InnerNonGeneric {} // expected-error{{type 'InnerNonGeneric' cannot be nested in generic type 'MidNonGeneric'}} - struct InnerGeneric {} // expected-error{{generic type 'InnerGeneric' cannot be nested in type 'MidNonGeneric'}} + struct MidNonGeneric { + struct InnerNonGeneric {} + struct InnerGeneric {} func roost(_ d: D) {} } - struct MidGeneric { // expected-error{{generic type 'MidGeneric' cannot be nested in type 'OuterGeneric'}} - struct InnerNonGeneric {} // expected-error{{type 'InnerNonGeneric' cannot be nested in generic type 'MidGeneric'}} - struct InnerGeneric {} // expected-error{{generic type 'InnerGeneric' cannot be nested in type 'MidGeneric'}} + struct MidGeneric { + struct InnerNonGeneric {} + struct InnerGeneric {} func nest(_ d: D, f: F) {} } @@ -58,7 +58,7 @@ class OuterNonGenericClass { } } - class InnerGenericClass : OuterNonGenericClass { // expected-error {{generic type 'InnerGenericClass' cannot be nested in type 'OuterNonGenericClass'}} + class InnerGenericClass : OuterNonGenericClass { override init() { super.init() } @@ -66,40 +66,40 @@ class OuterNonGenericClass { } class OuterGenericClass { - enum InnerNonGeneric { // expected-error {{type 'InnerNonGeneric' cannot be nested in generic type 'OuterGenericClass'}} + enum InnerNonGeneric { case Baz case Zab } - class InnerNonGenericBase { // expected-error {{type 'InnerNonGenericBase' cannot be nested in generic type 'OuterGenericClass'}} + class InnerNonGenericBase { init() {} } - class InnerNonGenericClass1 : InnerNonGenericBase { // expected-error {{type 'InnerNonGenericClass1' cannot be nested in generic type 'OuterGenericClass'}} + class InnerNonGenericClass1 : InnerNonGenericBase { override init() { super.init() } } - class InnerNonGenericClass2 : OuterGenericClass { // expected-error {{type 'InnerNonGenericClass2' cannot be nested in generic type 'OuterGenericClass'}} + class InnerNonGenericClass2 : OuterGenericClass { override init() { super.init() } } - class InnerNonGenericClass3 : OuterGenericClass { // expected-error {{type 'InnerNonGenericClass3' cannot be nested in generic type 'OuterGenericClass'}} + class InnerNonGenericClass3 : OuterGenericClass { override init() { super.init() } } - class InnerNonGenericClass4 : OuterGenericClass { // expected-error {{type 'InnerNonGenericClass4' cannot be nested in generic type 'OuterGenericClass'}} + class InnerNonGenericClass4 : OuterGenericClass { override init() { super.init() } } - class InnerGenericClass : OuterGenericClass { // expected-error {{type 'InnerGenericClass' cannot be nested in type 'OuterGenericClass'}} + class InnerGenericClass : OuterGenericClass { override init() { super.init() } @@ -108,7 +108,7 @@ class OuterGenericClass { // struct AnyStream { - struct StreamRange { // expected-error{{generic type 'StreamRange' cannot be nested in type 'AnyStream'}} + struct StreamRange { var index : Int var elements : S @@ -128,7 +128,7 @@ struct AnyStream { // Conform to the enumerable protocol. typealias Elements = StreamRange func getElements() -> Elements { - return Elements(index: 0, elements: input.makeIterator()) // expected-error {{'AnyStream.StreamRange' cannot be constructed because it has no accessible initializers}} + return Elements(index: 0, elements: input.makeIterator()) } } @@ -177,9 +177,9 @@ extension Bar { class X6 { let d: D init(_ value: T) { - d = D(value) // expected-error{{'<>' cannot be constructed because it has no accessible initializers}} + d = D(value) } - class D { // expected-error{{generic type 'D' cannot be nested in type 'X6'}} + class D { init(_ value: T2) {} } } @@ -193,17 +193,17 @@ struct GS { return gs } - struct Nested { // expected-error{{cannot be nested in generic type}} + struct Nested { func ff() -> GS { let gs = GS() return gs } } - struct NestedGeneric { // expected-note{{generic type 'NestedGeneric' declared here}} // expected-error{{generic type 'NestedGeneric' cannot be nested in type 'GS'}} + struct NestedGeneric { // expected-note{{generic type 'NestedGeneric' declared here}} func fff() -> (GS, NestedGeneric) { let gs = GS() - let ns = NestedGeneric() // expected-error {{'GS.NestedGeneric' cannot be constructed because it has no accessible initializers}} + let ns = NestedGeneric() return (gs, ns) } } @@ -227,12 +227,12 @@ struct HasNested { init(_ t: T, _ u: U) {} func f(_ t: T, u: U) -> (T, U) {} - struct InnerGeneric { // expected-error{{generic type 'InnerGeneric' cannot be nested in type 'HasNested'}} + struct InnerGeneric { init() {} func g(_ t: T, u: U, v: V) -> (T, U, V) {} } - struct Inner { // expected-error{{type 'Inner' cannot be nested in generic type 'HasNested'}} + struct Inner { init (_ x: T) {} func identity(_ x: T) -> T { return x } } @@ -245,7 +245,7 @@ func useNested(_ ii: Int, hni: HasNested, typealias InnerI = HasNested.Inner var innerI = InnerI(5) typealias InnerF = HasNested.Inner - var innerF : InnerF = innerI + var innerF : InnerF = innerI // expected-error{{cannot convert value of type 'InnerI' (aka 'HasNested.Inner') to specified type 'InnerF' (aka 'HasNested.Inner')}} _ = innerI.identity(i) i = innerI.identity(i) @@ -265,7 +265,7 @@ func useNested(_ ii: Int, hni: HasNested, var ids = xis.g(1, u: "Hello", v: 3.14159) ids = (2, "world", 2.71828) - xis = xfs + xis = xfs // expected-error{{cannot assign value of type 'HasNested.InnerGeneric' to type 'HasNested.InnerGeneric'}} } // Extensions of nested generic types diff --git a/test/decl/typealias/generic.swift b/test/decl/typealias/generic.swift index d6b95dff5c541..8dec55e5ffdad 100644 --- a/test/decl/typealias/generic.swift +++ b/test/decl/typealias/generic.swift @@ -1,4 +1,4 @@ -// RUN: %target-parse-verify-swift -enable-experimental-nested-generic-types +// RUN: %target-parse-verify-swift struct MyType { // expected-note {{declared here}} var a : TyA, b : TyB diff --git a/test/stdlib/RuntimeObjC.swift b/test/stdlib/RuntimeObjC.swift index e3ef74888f4aa..e8ec6024d836e 100644 --- a/test/stdlib/RuntimeObjC.swift +++ b/test/stdlib/RuntimeObjC.swift @@ -680,7 +680,7 @@ Reflection.test("MetatypeMirror") { expectEqual(expectedObjCProtocolConcrete, output) let compositionConcreteMetatype = (SomeNativeProto & SomeObjCProto).self - let expectedComposition = "- a.SomeNativeProto & a.SomeObjCProto #0\n" + let expectedComposition = "- a.SomeObjCProto & a.SomeNativeProto #0\n" output = "" dump(compositionConcreteMetatype, to: &output) expectEqual(expectedComposition, output) diff --git a/test/stdlib/TypeName.swift b/test/stdlib/TypeName.swift index eeefd78a5b5a1..7d12abb4bfd09 100644 --- a/test/stdlib/TypeName.swift +++ b/test/stdlib/TypeName.swift @@ -59,23 +59,23 @@ TypeNameTests.test("Prints") { typealias F2 = () -> () -> () typealias F3 = (() -> ()) -> () - expectEqual("(()) -> ()", _typeName(F.self)) - expectEqual("(()) -> (()) -> ()", _typeName(F2.self)) - expectEqual("(((()) -> ())) -> ()", _typeName(F3.self)) - expectEqual("(()) -> ()", _typeName((() -> ()).self)) - + expectEqual("() -> ()", _typeName(F.self)) + expectEqual("() -> () -> ()", _typeName(F2.self)) + expectEqual("(() -> ()) -> ()", _typeName(F3.self)) + expectEqual("() -> ()", _typeName((() -> ()).self)) + #if _runtime(_ObjC) typealias B = @convention(block) () -> () typealias B2 = () -> @convention(block) () -> () typealias B3 = (@convention(block) () -> ()) -> () - expectEqual("@convention(block) (()) -> ()", _typeName(B.self)) - expectEqual("(()) -> @convention(block) (()) -> ()", + expectEqual("@convention(block) () -> ()", _typeName(B.self)) + expectEqual("() -> @convention(block) () -> ()", _typeName(B2.self)) - expectEqual("((@convention(block) (()) -> ())) -> ()", + expectEqual("(@convention(block) () -> ()) -> ()", _typeName(B3.self)) #endif - expectEqual("((()) -> ()).Type", _typeName(F.Type.self)) + expectEqual("(() -> ()).Type", _typeName(F.Type.self)) expectEqual("main.C.Type", _typeName(C.Type.self)) expectEqual("main.C.Type.Type", _typeName(C.Type.Type.self)) expectEqual("Any.Type", _typeName(Any.Type.self)) @@ -88,7 +88,7 @@ TypeNameTests.test("Prints") { typealias Tup = (Any, F, C) - expectEqual("(Any, (()) -> (), main.C)", + expectEqual("(Any, () -> (), main.C)", _typeName(Tup.self)) } @@ -105,15 +105,15 @@ TypeNameTests.test("Inout") { expectEqual("(inout Swift.Int) -> ()", _typeName(IF.self)) expectEqual("(inout Swift.Int) -> (inout Swift.Int) -> ()", _typeName(IF2.self)) - expectEqual("(((inout Swift.Int) -> ())) -> ()", + expectEqual("((inout Swift.Int) -> ()) -> ()", _typeName(IF3.self)) - expectEqual("(inout ((Swift.Int) -> ())) -> ()", + expectEqual("(inout (Swift.Int) -> ()) -> ()", _typeName(IF3a.self)) - expectEqual("(inout ((Swift.Int) -> ())) -> ()", + expectEqual("(inout (Swift.Int) -> ()) -> ()", _typeName(IF3b.self)) - expectEqual("(((inout Swift.Int) -> ())) -> ()", + expectEqual("((inout Swift.Int) -> ()) -> ()", _typeName(IF3c.self)) - expectEqual("(inout ((()) -> ())) -> ()", + expectEqual("(inout () -> ()) -> ()", _typeName(IF4.self)) expectEqual("(inout Swift.Int, Any) -> ()", _typeName(IF5.self)) @@ -144,16 +144,37 @@ TypeNameTests.test("Functions") { return curry1Throws } - expectEqual("(()) -> ()", + expectEqual("() -> ()", _typeName(type(of: curry1))) - expectEqual("(()) -> (()) -> ()", + expectEqual("() -> () -> ()", _typeName(type(of: curry2))) - expectEqual("(()) throws -> (()) -> ()", + expectEqual("() throws -> () -> ()", _typeName(type(of: curry2Throws))) - expectEqual("(()) -> (()) throws -> ()", + expectEqual("() -> () throws -> ()", _typeName(type(of: curry3))) - expectEqual("(()) throws -> (()) throws -> ()", + expectEqual("() throws -> () throws -> ()", _typeName(type(of: curry3Throws))) } +class SomeOuterClass { + struct SomeInnerStruct {} + struct SomeInnerGenericStruct {} +} + +class SomeOuterGenericClass { + struct SomeInnerStruct {} + struct SomeInnerGenericStruct {} +} + +TypeNameTests.test("Nested") { + expectEqual("main.SomeOuterClass.SomeInnerStruct", + _typeName(SomeOuterClass.SomeInnerStruct.self)); + expectEqual("main.SomeOuterClass.SomeInnerGenericStruct", + _typeName(SomeOuterClass.SomeInnerGenericStruct.self)); + expectEqual("main.SomeOuterGenericClass.SomeInnerStruct", + _typeName(SomeOuterGenericClass.SomeInnerStruct.self)); + expectEqual("main.SomeOuterGenericClass.SomeInnerGenericStruct", + _typeName(SomeOuterGenericClass.SomeInnerGenericStruct.self)); +} + runAllTests()