diff --git a/test/Constraints/existential_metatypes.swift b/test/Constraints/existential_metatypes.swift index 3b03e5ef13d0b..b826fcf705e1f 100644 --- a/test/Constraints/existential_metatypes.swift +++ b/test/Constraints/existential_metatypes.swift @@ -86,6 +86,9 @@ func testP3(_ p: P3, something: Something) { p.withP3(Something.takeP3(something)) } -func testIUOToAny(_ t: AnyObject.Type!) { - let _: Any = t +func testIUOToAny(_ t: AnyObject.Type!) { // expected-note {{implicitly unwrapped parameter 't' declared here}} + let _: Any = t // expected-warning {{coercion of implicitly unwrappable value of type 'AnyObject.Type?' to 'Any' does not unwrap optional}} + // expected-note@-1 {{force-unwrap the value to avoid this warning}} + // expected-note@-2 {{provide a default value to avoid this warning}} + // expected-note@-3 {{explicitly cast to 'Any' with 'as Any' to silence this warning}} } diff --git a/test/Constraints/existential_metatypes4.swift b/test/Constraints/existential_metatypes4.swift new file mode 100644 index 0000000000000..8cefd4e230b98 --- /dev/null +++ b/test/Constraints/existential_metatypes4.swift @@ -0,0 +1,5 @@ +// RUN: %target-typecheck-verify-swift -swift-version 4 + +func testIUOToAny(_ t: AnyObject.Type!) { + let _: Any = t +} diff --git a/test/Migrator/stdlib_rename.swift b/test/Migrator/stdlib_rename.swift index d5ae2b3f56b38..242136c91ef29 100644 --- a/test/Migrator/stdlib_rename.swift +++ b/test/Migrator/stdlib_rename.swift @@ -1,5 +1,5 @@ // REQUIRES: objc_interop -// RUN: %empty-directory(%t) && %target-swift-frontend -c -update-code -primary-file %s -F %S/mock-sdk -emit-migrated-file-path %t/stdlib_rename.swift.result -emit-remap-file-path %t/stdlib_rename.swift.remap -o /dev/null +// RUN: %empty-directory(%t) && %target-swift-frontend -c -update-code -primary-file %s -F %S/mock-sdk -emit-migrated-file-path %t/stdlib_rename.swift.result -emit-remap-file-path %t/stdlib_rename.swift.remap -swift-version 4 -o /dev/null // RUN: diff -u %S/stdlib_rename.swift.expected %t/stdlib_rename.swift.result // RUN: %empty-directory(%t) && %target-swift-frontend -c -update-code -primary-file %s -F %S/mock-sdk -emit-migrated-file-path %t/stdlib_rename.swift.result -emit-remap-file-path %t/stdlib_rename.swift.remap -o /dev/null -swift-version 4.2 // RUN: diff -u %S/stdlib_rename.swift.expected %t/stdlib_rename.swift.result @@ -10,4 +10,4 @@ func test1(_ a: [String], s: String) { } func test2(_ s: String, c: Character) { _ = s.index(of: c) -} \ No newline at end of file +} diff --git a/test/Migrator/stdlib_rename.swift.expected b/test/Migrator/stdlib_rename.swift.expected index 04dadba8cf63e..c929a916d4253 100644 --- a/test/Migrator/stdlib_rename.swift.expected +++ b/test/Migrator/stdlib_rename.swift.expected @@ -1,5 +1,5 @@ // REQUIRES: objc_interop -// RUN: %empty-directory(%t) && %target-swift-frontend -c -update-code -primary-file %s -F %S/mock-sdk -emit-migrated-file-path %t/stdlib_rename.swift.result -emit-remap-file-path %t/stdlib_rename.swift.remap -o /dev/null +// RUN: %empty-directory(%t) && %target-swift-frontend -c -update-code -primary-file %s -F %S/mock-sdk -emit-migrated-file-path %t/stdlib_rename.swift.result -emit-remap-file-path %t/stdlib_rename.swift.remap -swift-version 4 -o /dev/null // RUN: diff -u %S/stdlib_rename.swift.expected %t/stdlib_rename.swift.result // RUN: %empty-directory(%t) && %target-swift-frontend -c -update-code -primary-file %s -F %S/mock-sdk -emit-migrated-file-path %t/stdlib_rename.swift.result -emit-remap-file-path %t/stdlib_rename.swift.remap -o /dev/null -swift-version 4.2 // RUN: diff -u %S/stdlib_rename.swift.expected %t/stdlib_rename.swift.result @@ -10,4 +10,4 @@ func test1(_ a: [String], s: String) { } func test2(_ s: String, c: Character) { _ = s.firstIndex(of: c) -} \ No newline at end of file +} diff --git a/test/stdlib/Filter.swift b/test/stdlib/Filter.swift index ca558c179bc77..58bce8be3dd59 100644 --- a/test/stdlib/Filter.swift +++ b/test/stdlib/Filter.swift @@ -2,7 +2,7 @@ // // This source file is part of the Swift.org open source project // -// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors +// Copyright (c) 2014 - 2020 Apple Inc. and the Swift project authors // Licensed under Apache License v2.0 with Runtime Library Exception // // See https://swift.org/LICENSE.txt for license information @@ -20,7 +20,7 @@ let FilterTests = TestSuite("Filter") // Check that the generic parameter is called 'Base'. protocol TestProtocol1 {} -extension LazyFilterIterator where Base : TestProtocol1 { +extension LazyFilterSequence.Iterator where Base : TestProtocol1 { var _baseIsTestProtocol1: Bool { fatalError("not implemented") } diff --git a/test/stdlib/Map.swift b/test/stdlib/Map.swift index 0946f184dae0b..f19de6bedfb44 100644 --- a/test/stdlib/Map.swift +++ b/test/stdlib/Map.swift @@ -15,7 +15,7 @@ // Check that the generic parameters are called 'Base' and 'Element'. protocol TestProtocol1 {} -extension LazyMapIterator where Base : TestProtocol1, Element : TestProtocol1 { +extension LazyMapSequence.Iterator where Base : TestProtocol1, Element : TestProtocol1 { var _baseIsTestProtocol1: Bool { fatalError("not implemented") } diff --git a/test/stdlib/Mirror.swift b/test/stdlib/Mirror.swift index 4755be399ad11..a1110308ff182 100644 --- a/test/stdlib/Mirror.swift +++ b/test/stdlib/Mirror.swift @@ -969,6 +969,7 @@ mirrors.test("Invalid Path Type") _ = m.descendant(X()) } +#if swift(<5) // CustomPlaygroundQuickLookable was obsoleted in Swift 5 mirrors.test("PlaygroundQuickLook") { // Customization works. struct CustomQuickie : CustomPlaygroundQuickLookable { @@ -1036,6 +1037,7 @@ mirrors.test("_DefaultCustomPlaygroundQuickLookable") { default: expectUnreachable("FancyChild custom quicklookable was expected") } } +#endif mirrors.test("String.init") { expectEqual("42", String(42)) diff --git a/test/stdlib/ObsoleteTypenames.swift b/test/stdlib/ObsoleteTypenames.swift new file mode 100644 index 0000000000000..ebdfb247bc1ec --- /dev/null +++ b/test/stdlib/ObsoleteTypenames.swift @@ -0,0 +1,48 @@ +//===----------------------------------------------------------------------===// +// +// This source file is part of the Swift.org open source project +// +// Copyright (c) 2020 Apple Inc. and the Swift project authors +// Licensed under Apache License v2.0 with Runtime Library Exception +// +// See https://swift.org/LICENSE.txt for license information +// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors +// +//===----------------------------------------------------------------------===// +// RUN: %empty-directory(%t) +// RUN: %target-build-swift -swift-version 4 %s -o %t/Filter4 +// RUN: %target-codesign %t/Filter4 +// RUN: %target-run %t/Filter4 +// REQUIRES: executable_test + +// Tests for typealiases obsoleted in Swift 5 + +import StdlibUnittest + +let suite = TestSuite("Filter4") +defer { runAllTests() } + +suite.test("obsolete names") { + expectEqualType( + LazyFilterIterator<[Int]>.self, + LazyFilterSequence<[Int]>.Iterator.self) + expectEqualType( + LazyMapBidirectionalCollection<[Int], Int>.self, + LazyMapCollection<[Int], Int>.self) + expectEqualType( + LazyMapRandomAccessCollection<[Int], Int>.self, + LazyMapCollection<[Int], Int>.self) + expectEqualType( + LazyMapIterator<[Int], Int>.self, + LazyMapSequence<[Int], Int>.Iterator.self) + expectEqualType( + UnsafeBufferPointerIterator.self, + UnsafeBufferPointer.Iterator.self) + expectEqualType( + IteratorOverOne.self, + CollectionOfOne.Iterator.self) + expectEqualType( + EmptyIterator.self, + EmptyCollection.Iterator.self) +} + diff --git a/test/stdlib/Reflection_objc.swift b/test/stdlib/Reflection_objc.swift index 0ec4732b6b6f5..a4e43ba935b48 100644 --- a/test/stdlib/Reflection_objc.swift +++ b/test/stdlib/Reflection_objc.swift @@ -77,94 +77,6 @@ print("We cannot reflect \(ComparisonResult.orderedAscending) yet") print("NSURL:") dump(NSURL(fileURLWithPath: "/Volumes", isDirectory: true)) -// -- Check that quick look Cocoa objects get binned correctly to their -// associated enum tag. - -// CHECK-NEXT: got the expected quick look text -switch PlaygroundQuickLook(reflecting: "woozle wuzzle" as NSString) { -case .text("woozle wuzzle"): - print("got the expected quick look text") -case let x: - print("NSString: got something else: \(x)") -} - -// CHECK-NEXT: foobar -let somesubclassofnsstring = ("foo" + "bar") as NSString -switch PlaygroundQuickLook(reflecting: somesubclassofnsstring) { - case .text(let text): print(text) - case let x: print("not the expected quicklook: \(x)") -} - -// CHECK-NEXT: got the expected quick look attributed string -let astr = NSAttributedString(string: "yizzle pizzle") -switch PlaygroundQuickLook(reflecting: astr) { -case .attributedString(let astr2 as NSAttributedString) -where astr == astr2: - print("got the expected quick look attributed string") -case let x: - print("NSAttributedString: got something else: \(x)") -} - -// CHECK-NEXT: got the expected quick look int -switch PlaygroundQuickLook(reflecting: Int.max as NSNumber) { -case .int(+Int64(Int.max)): - print("got the expected quick look int") -case let x: - print("NSNumber(Int.max): got something else: \(x)") -} - -// CHECK-NEXT: got the expected quick look uint -switch PlaygroundQuickLook(reflecting: NSNumber(value: UInt64.max)) { -case .uInt(UInt64.max): - print("got the expected quick look uint") -case let x: - print("NSNumber(Int64.max): got something else: \(x)") -} - -// CHECK-NEXT: got the expected quick look double -switch PlaygroundQuickLook(reflecting: 22.5 as NSNumber) { -case .double(22.5): - print("got the expected quick look double") -case let x: - print("NSNumber(22.5): got something else: \(x)") -} - -// CHECK-NEXT: got the expected quick look float -switch PlaygroundQuickLook(reflecting: Float32(1.25)) { -case .float(1.25): - print("got the expected quick look float") -case let x: - print("NSNumber(Float32(1.25)): got something else: \(x)") -} - -// CHECK-NEXT: got the expected quick look image -// CHECK-NEXT: got the expected quick look color -// CHECK-NEXT: got the expected quick look bezier path - -let image = OSImage(contentsOfFile:CommandLine.arguments[1])! -switch PlaygroundQuickLook(reflecting: image) { -case .image(let image2 as OSImage) where image === image2: - print("got the expected quick look image") -case let x: - print("OSImage: got something else: \(x)") -} - -let color = OSColor.black -switch PlaygroundQuickLook(reflecting: color) { -case .color(let color2 as OSColor) where color === color2: - print("got the expected quick look color") -case let x: - print("OSColor: got something else: \(x)") -} - -let path = OSBezierPath() -switch PlaygroundQuickLook(reflecting: path) { -case .bezierPath(let path2 as OSBezierPath) where path === path2: - print("got the expected quick look bezier path") -case let x: - print("OSBezierPath: got something else: \(x)") -} - // CHECK-LABEL: Reflecting NSArray: // CHECK-NEXT: [ 1 2 3 4 5 ] print("Reflecting NSArray:") @@ -211,82 +123,6 @@ dump(CGSize(width: 30, height: 60)) // CHECK-NEXT: height: 150.0 dump(CGRect(x: 50, y: 60, width: 100, height: 150)) -// rdar://problem/18513769 -- Make sure that QuickLookObject lookup correctly -// manages memory. - -@objc class CanaryBase { - deinit { - print("\(type(of: self)) overboard") - } - - required init() { } -} - -var CanaryHandle = false - -class IsDebugQLO : CanaryBase, CustomStringConvertible { - @objc var description: String { - return "I'm a QLO" - } -} - -class HasDebugQLO : CanaryBase { - @objc var debugQuickLookObject: AnyObject { - return IsDebugQLO() - } -} - -class HasNumberQLO : CanaryBase { - @objc var debugQuickLookObject: AnyObject { - let number = NSNumber(value: 97210) - return number - } -} - -class HasAttributedQLO : CanaryBase { - @objc var debugQuickLookObject: AnyObject { - let str = NSAttributedString(string: "attributed string") - objc_setAssociatedObject(str, &CanaryHandle, CanaryBase(), - .OBJC_ASSOCIATION_RETAIN_NONATOMIC) - return str - } -} - -class HasStringQLO : CanaryBase { - @objc var debugQuickLookObject: AnyObject { - let str = NSString(string: "plain string") - objc_setAssociatedObject(str, &CanaryHandle, CanaryBase(), - .OBJC_ASSOCIATION_RETAIN_NONATOMIC) - return str - } -} - -func testQLO(_ type: T.Type) { - autoreleasepool { - _ = PlaygroundQuickLook(reflecting: type.init()) - } -} - -testQLO(IsDebugQLO.self) -// CHECK-NEXT: IsDebugQLO overboard - -testQLO(HasDebugQLO.self) -// CHECK-NEXT: HasDebugQLO overboard -// CHECK-NEXT: IsDebugQLO overboard - -testQLO(HasNumberQLO.self) -// CHECK-NEXT: HasNumberQLO overboard -// TODO: tagged numbers are immortal, so we can't reliably check for -// cleanup here - -testQLO(HasAttributedQLO.self) -// CHECK-NEXT: HasAttributedQLO overboard -// CHECK-NEXT: CanaryBase overboard - -testQLO(HasStringQLO.self) -// CHECK-NEXT: HasStringQLO overboard -// CHECK-NEXT: CanaryBase overboard - let x = float4(0) print("float4 has \(Mirror(reflecting: x).children.count) children") // CHECK-NEXT: float4 has 1 children diff --git a/test/stdlib/Reflection_objc4.swift b/test/stdlib/Reflection_objc4.swift new file mode 100644 index 0000000000000..6504dbc922824 --- /dev/null +++ b/test/stdlib/Reflection_objc4.swift @@ -0,0 +1,203 @@ +// RUN: %empty-directory(%t) +// +// RUN: %target-clang %S/Inputs/Mirror/Mirror.mm -c -o %t/Mirror.mm.o -g +// RUN: %target-build-swift -swift-version 4 -parse-stdlib %s -module-name Reflection -I %S/Inputs/Mirror/ -Xlinker %t/Mirror.mm.o -o %t/a.out +// RUN: %target-codesign %t/a.out +// RUN: %{python} %S/../Inputs/timeout.py 360 %target-run %t/a.out %S/Inputs/shuffle.jpg | %FileCheck %s +// FIXME: timeout wrapper is necessary because the ASan test runs for hours + +// REQUIRES: executable_test +// REQUIRES: objc_interop + +// +// DO NOT add more tests to this file. Add them to test/1_stdlib/Runtime.swift. +// + + +import Swift +import Foundation +import simd + +#if canImport(AppKit) +import AppKit + +typealias OSImage = NSImage +typealias OSColor = NSColor +typealias OSBezierPath = NSBezierPath +#elseif canImport(UIKit) +import UIKit + +typealias OSImage = UIImage +typealias OSColor = UIColor +typealias OSBezierPath = UIBezierPath +#else +#error("Platform does not support UIKit or AppKit!") +#endif + +// CHECK-LABEL: PlaygroundQuickLook: +print("PlaygroundQuickLook:") + +// -- Check that quick look Cocoa objects get binned correctly to their +// associated enum tag. + +// CHECK-NEXT: got the expected quick look text +switch PlaygroundQuickLook(reflecting: "woozle wuzzle" as NSString) { +case .text("woozle wuzzle"): + print("got the expected quick look text") +case let x: + print("NSString: got something else: \(x)") +} + +// CHECK-NEXT: foobar +let somesubclassofnsstring = ("foo" + "bar") as NSString +switch PlaygroundQuickLook(reflecting: somesubclassofnsstring) { + case .text(let text): print(text) + case let x: print("not the expected quicklook: \(x)") +} + +// CHECK-NEXT: got the expected quick look attributed string +let astr = NSAttributedString(string: "yizzle pizzle") +switch PlaygroundQuickLook(reflecting: astr) { +case .attributedString(let astr2 as NSAttributedString) +where astr == astr2: + print("got the expected quick look attributed string") +case let x: + print("NSAttributedString: got something else: \(x)") +} + +// CHECK-NEXT: got the expected quick look int +switch PlaygroundQuickLook(reflecting: Int.max as NSNumber) { +case .int(+Int64(Int.max)): + print("got the expected quick look int") +case let x: + print("NSNumber(Int.max): got something else: \(x)") +} + +// CHECK-NEXT: got the expected quick look uint +switch PlaygroundQuickLook(reflecting: NSNumber(value: UInt64.max)) { +case .uInt(UInt64.max): + print("got the expected quick look uint") +case let x: + print("NSNumber(Int64.max): got something else: \(x)") +} + +// CHECK-NEXT: got the expected quick look double +switch PlaygroundQuickLook(reflecting: 22.5 as NSNumber) { +case .double(22.5): + print("got the expected quick look double") +case let x: + print("NSNumber(22.5): got something else: \(x)") +} + +// CHECK-NEXT: got the expected quick look float +switch PlaygroundQuickLook(reflecting: Float32(1.25)) { +case .float(1.25): + print("got the expected quick look float") +case let x: + print("NSNumber(Float32(1.25)): got something else: \(x)") +} + +// CHECK-NEXT: got the expected quick look image +// CHECK-NEXT: got the expected quick look color +// CHECK-NEXT: got the expected quick look bezier path + +let image = OSImage(contentsOfFile:CommandLine.arguments[1])! +switch PlaygroundQuickLook(reflecting: image) { +case .image(let image2 as OSImage) where image === image2: + print("got the expected quick look image") +case let x: + print("OSImage: got something else: \(x)") +} + +let color = OSColor.black +switch PlaygroundQuickLook(reflecting: color) { +case .color(let color2 as OSColor) where color === color2: + print("got the expected quick look color") +case let x: + print("OSColor: got something else: \(x)") +} + +let path = OSBezierPath() +switch PlaygroundQuickLook(reflecting: path) { +case .bezierPath(let path2 as OSBezierPath) where path === path2: + print("got the expected quick look bezier path") +case let x: + print("OSBezierPath: got something else: \(x)") +} + +// rdar://problem/18513769 -- Make sure that QuickLookObject lookup correctly +// manages memory. + +@objc class CanaryBase { + deinit { + print("\(type(of: self)) overboard") + } + + required init() { } +} + +var CanaryHandle = false + +class IsDebugQLO : CanaryBase, CustomStringConvertible { + @objc var description: String { + return "I'm a QLO" + } +} + +class HasDebugQLO : CanaryBase { + @objc var debugQuickLookObject: AnyObject { + return IsDebugQLO() + } +} + +class HasNumberQLO : CanaryBase { + @objc var debugQuickLookObject: AnyObject { + let number = NSNumber(value: 97210) + return number + } +} + +class HasAttributedQLO : CanaryBase { + @objc var debugQuickLookObject: AnyObject { + let str = NSAttributedString(string: "attributed string") + objc_setAssociatedObject(str, &CanaryHandle, CanaryBase(), + .OBJC_ASSOCIATION_RETAIN_NONATOMIC) + return str + } +} + +class HasStringQLO : CanaryBase { + @objc var debugQuickLookObject: AnyObject { + let str = NSString(string: "plain string") + objc_setAssociatedObject(str, &CanaryHandle, CanaryBase(), + .OBJC_ASSOCIATION_RETAIN_NONATOMIC) + return str + } +} + +func testQLO(_ type: T.Type) { + autoreleasepool { + _ = PlaygroundQuickLook(reflecting: type.init()) + } +} + +testQLO(IsDebugQLO.self) +// CHECK-NEXT: IsDebugQLO overboard + +testQLO(HasDebugQLO.self) +// CHECK-NEXT: HasDebugQLO overboard +// CHECK-NEXT: IsDebugQLO overboard + +testQLO(HasNumberQLO.self) +// CHECK-NEXT: HasNumberQLO overboard +// TODO: tagged numbers are immortal, so we can't reliably check for +// cleanup here + +testQLO(HasAttributedQLO.self) +// CHECK-NEXT: HasAttributedQLO overboard +// CHECK-NEXT: CanaryBase overboard + +testQLO(HasStringQLO.self) +// CHECK-NEXT: HasStringQLO overboard +// CHECK-NEXT: CanaryBase overboard + diff --git a/test/stdlib/RuntimeObjC.swift b/test/stdlib/RuntimeObjC.swift index 75e96237b6079..74bfdcee78b0b 100644 --- a/test/stdlib/RuntimeObjC.swift +++ b/test/stdlib/RuntimeObjC.swift @@ -164,7 +164,7 @@ func withSwiftObjectCanary( swiftObjectCanaryCount = 0 autoreleasepool { - var valueWithCanary = createValue() + let valueWithCanary = createValue() expectEqual(1, swiftObjectCanaryCount, stackTrace: stackTrace) check(valueWithCanary) } @@ -233,7 +233,7 @@ Runtime.test("bridgeToObjectiveC") { expectEqual(42, (_bridgeAnythingToObjectiveC(BridgedLargeValueType(value: 42)) as! ClassA).value) - var bridgedVerbatimRef = BridgedVerbatimRefType() + let bridgedVerbatimRef = BridgedVerbatimRefType() expectTrue(_bridgeAnythingToObjectiveC(bridgedVerbatimRef) === bridgedVerbatimRef) } @@ -284,7 +284,7 @@ Runtime.test("forceBridgeFromObjectiveC") { expectNil(_conditionallyBridgeFromObjectiveC( ClassA(value: 42), BridgedVerbatimRefType.self)) - var bridgedVerbatimRef = BridgedVerbatimRefType() + let bridgedVerbatimRef = BridgedVerbatimRefType() expectTrue(_forceBridgeFromObjectiveC( bridgedVerbatimRef, BridgedVerbatimRefType.self) === bridgedVerbatimRef) expectTrue(_conditionallyBridgeFromObjectiveC( @@ -435,7 +435,7 @@ Runtime.test("typeByName") { Runtime.test("casting AnyObject to class metatypes") { do { - var ao: AnyObject = SomeClass.self + let ao: AnyObject = SomeClass.self expectTrue(ao as? Any.Type == SomeClass.self) expectTrue(ao as? AnyClass == SomeClass.self) expectTrue(ao as? SomeClass.Type == SomeClass.self) @@ -453,7 +453,7 @@ Runtime.test("casting AnyObject to class metatypes") { } do { - var a : Any = SomeNSObjectSubclass() + let a : Any = SomeNSObjectSubclass() expectTrue(a as? Any.Type == nil) expectTrue(a as? AnyClass == nil) } @@ -477,7 +477,7 @@ RuntimeFoundationWrappers.test("_stdlib_NSObject_isEqual/NoLeak") { let a = NSObjectCanary() let b = NSObjectCanary() expectEqual(2, nsObjectCanaryCount) - _stdlib_NSObject_isEqual(a, b) + _ = _stdlib_NSObject_isEqual(a, b) } expectEqual(0, nsObjectCanaryCount) } @@ -510,7 +510,7 @@ RuntimeFoundationWrappers.test("_stdlib_CFStringCreateCopy/NoLeak") { autoreleasepool { let a = NSStringCanary() expectEqual(1, nsStringCanaryCount) - _stdlib_binary_CFStringCreateCopy(a) + _ = _stdlib_binary_CFStringCreateCopy(a) } expectEqual(0, nsStringCanaryCount) } @@ -520,7 +520,7 @@ RuntimeFoundationWrappers.test("_stdlib_CFStringGetLength/NoLeak") { autoreleasepool { let a = NSStringCanary() expectEqual(1, nsStringCanaryCount) - _stdlib_binary_CFStringGetLength(a) + _ = _stdlib_binary_CFStringGetLength(a) } expectEqual(0, nsStringCanaryCount) } @@ -530,7 +530,7 @@ RuntimeFoundationWrappers.test("_stdlib_CFStringGetCharactersPtr/NoLeak") { autoreleasepool { let a = NSStringCanary() expectEqual(1, nsStringCanaryCount) - _stdlib_binary_CFStringGetCharactersPtr(a) + _ = _stdlib_binary_CFStringGetCharactersPtr(a) } expectEqual(0, nsStringCanaryCount) } @@ -647,7 +647,7 @@ Reflection.test("CGRect") { Reflection.test("Unmanaged/nil") { var output = "" - var optionalURL: Unmanaged? + let optionalURL: Unmanaged? = nil dump(optionalURL, to: &output) let expected = "- nil\n" @@ -657,7 +657,7 @@ Reflection.test("Unmanaged/nil") { Reflection.test("Unmanaged/not-nil") { var output = "" - var optionalURL: Unmanaged? = + let optionalURL: Unmanaged? = Unmanaged.passRetained(CFURLCreateWithString(nil, "http://llvm.org/" as CFString, nil)) dump(optionalURL, to: &output) @@ -676,7 +676,7 @@ Reflection.test("TupleMirror/NoLeak") { do { nsObjectCanaryCount = 0 autoreleasepool { - var tuple = (1, NSObjectCanary()) + let tuple = (1, NSObjectCanary()) expectEqual(1, nsObjectCanaryCount) var output = "" dump(tuple, to: &output) @@ -686,7 +686,7 @@ Reflection.test("TupleMirror/NoLeak") { do { nsObjectCanaryCount = 0 autoreleasepool { - var tuple = (1, NSObjectCanaryStruct()) + let tuple = (1, NSObjectCanaryStruct()) expectEqual(1, nsObjectCanaryCount) var output = "" dump(tuple, to: &output) @@ -696,7 +696,7 @@ Reflection.test("TupleMirror/NoLeak") { do { swiftObjectCanaryCount = 0 autoreleasepool { - var tuple = (1, SwiftObjectCanary()) + let tuple = (1, SwiftObjectCanary()) expectEqual(1, swiftObjectCanaryCount) var output = "" dump(tuple, to: &output) @@ -706,7 +706,7 @@ Reflection.test("TupleMirror/NoLeak") { do { swiftObjectCanaryCount = 0 autoreleasepool { - var tuple = (1, SwiftObjectCanaryStruct()) + let tuple = (1, SwiftObjectCanaryStruct()) expectEqual(1, swiftObjectCanaryCount) var output = "" dump(tuple, to: &output) @@ -750,6 +750,7 @@ Reflection.test("NSObject is properly CustomDebugStringConvertible") { expectEqual(String(reflecting: object), object.debugDescription) } +#if swift(<5) // PlaygroundQuickLook(reflecting:) was obsoleted in Swift 5 Reflection.test("NSRange QuickLook") { let rng = NSRange(location:Int.min, length:5) let ql = PlaygroundQuickLook(reflecting: rng) @@ -761,6 +762,7 @@ Reflection.test("NSRange QuickLook") { expectUnreachable("PlaygroundQuickLook for NSRange did not match Range") } } +#endif class SomeSubclass : SomeClass {} diff --git a/test/stdlib/StringDiagnostics.swift b/test/stdlib/StringDiagnostics.swift index c3fde8ff884f5..64cbc291e129a 100644 --- a/test/stdlib/StringDiagnostics.swift +++ b/test/stdlib/StringDiagnostics.swift @@ -13,13 +13,11 @@ func testIntSubscripting(s: String, i: Int) { _ = s[17..<20] // expected-error{{'subscript(_:)' is unavailable: cannot subscript String with an integer range, use a String.Index range instead.}} _ = s[17...20] // expected-error{{'subscript(_:)' is unavailable: cannot subscript String with an integer range, use a String.Index range instead.}} + let r1 = 17 ..< 20 + let r2 = 17 ... 20 _ = s[Range(i...i)] // expected-error{{'subscript(_:)' is unavailable: cannot subscript String with an integer range, use a String.Index range instead.}} - _ = s[Range(17..<20)] // expected-error{{'subscript(_:)' is unavailable: cannot subscript String with an integer range, use a String.Index range instead.}} - _ = s[Range(17...20)] // expected-error{{'subscript(_:)' is unavailable: cannot subscript String with an integer range, use a String.Index range instead.}} - - _ = s[Range(i...i)] // expected-error{{'subscript(_:)' is unavailable: cannot subscript String with an integer range, use a String.Index range instead.}} - _ = s[Range(17..<20)] // expected-error{{'subscript(_:)' is unavailable: cannot subscript String with an integer range, use a String.Index range instead.}} - _ = s[Range(17...20)] // expected-error{{'subscript(_:)' is unavailable: cannot subscript String with an integer range, use a String.Index range instead.}} + _ = s[r1] // expected-error{{'subscript(_:)' is unavailable: cannot subscript String with an integer range, use a String.Index range instead.}} + _ = s[r2] // expected-error{{'subscript(_:)' is unavailable: cannot subscript String with an integer range, use a String.Index range instead.}} } func testNonAmbiguousStringComparisons() { diff --git a/test/stdlib/StringFlatMap.swift b/test/stdlib/StringFlatMap.swift index 2a214849d100d..b404c0d2e5f99 100644 --- a/test/stdlib/StringFlatMap.swift +++ b/test/stdlib/StringFlatMap.swift @@ -1,5 +1,5 @@ // RUN: %empty-directory(%t) -// RUN: %target-build-swift %s -o %t/a.out && %target-codesign %t/a.out && %target-run %t/a.out +// RUN: %target-build-swift -swift-version 4 %s -o %t/a.out && %target-codesign %t/a.out && %target-run %t/a.out // REQUIRES: executable_test diff --git a/test/stdlib/TestData.swift b/test/stdlib/TestData.swift index 3acb918a35742..1ad94e6cdf658 100644 --- a/test/stdlib/TestData.swift +++ b/test/stdlib/TestData.swift @@ -3896,7 +3896,7 @@ class TestData : TestDataSuper { let slice = data[3...] // Bar let range = slice.range(of: "a".data(using: .ascii)!) - expectEqual(range, Range(4..<5)) + expectEqual(range, 4..<5) } func test_nsdataSequence() { diff --git a/test/stdlib/TestIndexSet.swift b/test/stdlib/TestIndexSet.swift index c1529790e6f84..3ac59b00825f7 100644 --- a/test/stdlib/TestIndexSet.swift +++ b/test/stdlib/TestIndexSet.swift @@ -234,7 +234,7 @@ class TestIndexSet : TestIndexSetSuper { expectEqual(ranges.count, view.count) for i in 0 ..< min(ranges.count, view.count) { - expectEqual(Range(ranges[i]), Range(view[i])) + expectEqual(ranges[i], view[i]) } } @@ -243,8 +243,8 @@ class TestIndexSet : TestIndexSetSuper { var indexes = IndexSet() indexes.insert(integersIn: 2..<5) indexes.insert(integersIn: 8...10) - indexes.insert(integersIn: Range(15..<20)) - indexes.insert(integersIn: Range(30...39)) + indexes.insert(integersIn: 15..<20) + indexes.insert(integersIn: 30...39) indexes.insert(integersIn: 60..<80) // Empty ranges should yield no results: diff --git a/test/stdlib/TestMeasurement.swift b/test/stdlib/TestMeasurement.swift index ca39f49dc1086..d348df260fc2d 100644 --- a/test/stdlib/TestMeasurement.swift +++ b/test/stdlib/TestMeasurement.swift @@ -32,8 +32,8 @@ class MyDimensionalUnit : Dimension { class var unitMegaA : MyDimensionalUnit { return MyDimensionalUnit(symbol: "Ma", converter: UnitConverterLinear(coefficient: 1_000_000)) } - override class func baseUnit() -> MyDimensionalUnit { - return MyDimensionalUnit.unitA + override class func baseUnit() -> Self { + return MyDimensionalUnit.unitA as! Self } } diff --git a/test/stdlib/UnsafePointer.swift.gyb b/test/stdlib/UnsafePointer.swift.gyb index 568f34fb22732..0d6c2ecbc699e 100644 --- a/test/stdlib/UnsafePointer.swift.gyb +++ b/test/stdlib/UnsafePointer.swift.gyb @@ -28,7 +28,7 @@ extension UnsafeMutablePointer where Pointee : TestProtocol1 { } // Check that the generic parameter is called 'Element'. -extension UnsafeBufferPointerIterator where Element : TestProtocol1 { +extension UnsafeBufferPointer.Iterator where Element : TestProtocol1 { var _elementIsTestProtocol1: Bool { fatalError("not implemented") } @@ -61,12 +61,12 @@ var OpaquePointerTestSuite = TestSuite("OpaquePointer") ${SelfName}TestSuite.test("initFromOpaquePointer") { let other = OpaquePointer(bitPattern: 0x12345678)! let ptr = ${SelfType}(other) - expectEqual(0x12345678, unsafeBitCast(ptr, to: Int.self)) + expectEqual(0x12345678, Int(bitPattern: ptr)) let optionalOther: Optional = other let optionalPointer = ${SelfType}(optionalOther) expectNotNil(optionalPointer) - expectEqual(0x12345678, unsafeBitCast(optionalPointer, to: Int.self)) + expectEqual(0x12345678, Int(bitPattern: optionalPointer)) let nilOther: Optional = nil let nilPointer = ${SelfType}(nilOther) @@ -81,7 +81,7 @@ ${SelfName}TestSuite.test("initFromOpaquePointer") { UnsafeMutableRawPointerTestSuite.test("initFromMutating") { let other = UnsafeRawPointer(bitPattern: 0x12345678)! let ptr = UnsafeMutableRawPointer(mutating: other) - expectEqual(0x12345678, unsafeBitCast(ptr, to: Int.self)) + expectEqual(0x12345678, Int(bitPattern: ptr)) let optionalOther: Optional = other let optionalPointer = UnsafeMutableRawPointer(mutating: optionalOther) @@ -175,12 +175,12 @@ ${SelfName}TestSuite.test("toInteger") { ${SelfName}TestSuite.test("initFromUnsafeMutablePointer") { let other = UnsafeMutablePointer(bitPattern: 0x12345678)! let ptr = ${SelfType}(other) - expectEqual(0x12345678, unsafeBitCast(ptr, to: Int.self)) + expectEqual(0x12345678, Int(bitPattern: ptr)) let optionalOther: Optional = other let optionalPointer = ${SelfType}(optionalOther) expectNotNil(optionalPointer) - expectEqual(0x12345678, unsafeBitCast(optionalPointer, to: Int.self)) + expectEqual(0x12345678, Int(bitPattern: optionalPointer)) let nilOther: Optional> = nil let nilPointer = ${SelfType}(nilOther) @@ -196,12 +196,12 @@ ${SelfName}TestSuite.test("initFromUnsafeMutablePointer") { ${SelfName}TestSuite.test("initFromUnsafePointer") { let other = UnsafePointer(bitPattern: 0x12345678)! let ptr = ${SelfType}(other) - expectEqual(0x12345678, unsafeBitCast(ptr, to: Int.self)) + expectEqual(0x12345678, Int(bitPattern: ptr)) let optionalOther: Optional = other let optionalPointer = ${SelfType}(optionalOther) expectNotNil(optionalPointer) - expectEqual(0x12345678, unsafeBitCast(optionalPointer, to: Int.self)) + expectEqual(0x12345678, Int(bitPattern: optionalPointer)) let nilOther: Optional> = nil let nilPointer = ${SelfType}(nilOther) @@ -213,7 +213,7 @@ ${SelfName}TestSuite.test("initFromUnsafePointer") { UnsafeRawPointerTestSuite.test("initFromUnsafeMutableRawPointer") { let other = UnsafeMutableRawPointer(bitPattern: 0x12345678)! let ptr = UnsafeRawPointer(other) - expectEqual(0x12345678, unsafeBitCast(ptr, to: Int.self)) + expectEqual(0x12345678, Int(bitPattern: ptr)) let optionalOther: Optional = other let optionalPointer = UnsafeRawPointer(optionalOther) @@ -357,7 +357,7 @@ UnsafeMutablePointerTestSuite.test("initialize:from:.Right") { } UnsafeMutablePointerTestSuite.test("initialize:from:/immutable") { - var ptr = UnsafeMutablePointer.allocate(capacity: 3) + let ptr = UnsafeMutablePointer.allocate(capacity: 3) defer { ptr.deinitialize(count: 3) ptr.deallocate() @@ -372,7 +372,7 @@ UnsafeMutablePointerTestSuite.test("initialize:from:/immutable") { } UnsafeMutablePointerTestSuite.test("assign/immutable") { - var ptr = UnsafeMutablePointer.allocate(capacity: 2) + let ptr = UnsafeMutablePointer.allocate(capacity: 2) defer { ptr.deinitialize(count: 2) ptr.deallocate() @@ -462,9 +462,9 @@ ${SelfName}TestSuite.test("withMemoryRebound") { let ptrI = ${SelfName}(mutablePtrI) ptrI.withMemoryRebound(to: UInt.self, capacity: 4) { // Make sure the closure argument isa $SelfName - var ptrU: ${SelfName} = $0 + let ptrU: ${SelfName} = $0 // and that the element type is UInt. - var mutablePtrU = UnsafeMutablePointer(mutating: ptrU) + let mutablePtrU = UnsafeMutablePointer(mutating: ptrU) expectType(UInt.self, &mutablePtrU.pointee) } } diff --git a/test/stdlib/UnsafeRawPointer.swift b/test/stdlib/UnsafeRawPointer.swift index 6f98ce9a0e561..ebf998139aa65 100644 --- a/test/stdlib/UnsafeRawPointer.swift +++ b/test/stdlib/UnsafeRawPointer.swift @@ -42,8 +42,12 @@ UnsafeMutableRawPointerExtraTestSuite.test("initializeMemory") { expectEqual(2, ptrM2[1].number) expectEqual(2, ptrM2[2].number) - ptrM = p1.initializeMemory( - as: Missile.self, from: (1...3).map(Missile.init)) + (1...3).map(Missile.init).withUnsafeBufferPointer { b in + ptrM = p1.initializeMemory( + as: Missile.self, + from: b.baseAddress!, + count: b.count) + } defer { ptrM.deinitialize(count: 3) } @@ -79,7 +83,9 @@ UnsafeMutableRawPointerExtraTestSuite.test("load/store") { defer { p1.deallocate() } - let ptrI = p1.initializeMemory(as: Int.self, from: 1...3) + let ptrI = [1, 2, 3].withUnsafeBufferPointer { b in + p1.initializeMemory(as: Int.self, from: b.baseAddress!, count: b.count) + } defer { ptrI.deinitialize(count: 3) } diff --git a/test/stdlib/simd_diagnostics.swift b/test/stdlib/simd_diagnostics.swift index 16d48b7bbac4d..70f4b8a0826d4 100644 --- a/test/stdlib/simd_diagnostics.swift +++ b/test/stdlib/simd_diagnostics.swift @@ -5,15 +5,15 @@ import simd -let a = int4(0) + int4(0) // expected-error{{'+' is unavailable: integer vector types do not support checked arithmetic; use the wrapping operator '&+' instead}} -let b = int4(0) - int4(0) // expected-error{{'-' is unavailable: integer vector types do not support checked arithmetic; use the wrapping operator '&-' instead}} -let c = int4(0) * int4(0) // expected-error{{'*' is unavailable: integer vector types do not support checked arithmetic; use the wrapping operator '&*' instead}} -let x = int4(0) * (0 as Int32) // expected-error{{'*' is unavailable: integer vector types do not support checked arithmetic; use the wrapping operator '&*' instead}} -let y = (0 as Int32) * int4(0) // expected-error{{'*' is unavailable: integer vector types do not support checked arithmetic; use the wrapping operator '&*' instead}} +let a = SIMD4(repeating: 0) + SIMD4(repeating: 0) // expected-error{{'+' is unavailable: integer vector types do not support checked arithmetic; use the wrapping operator '&+' instead}} +let b = SIMD4(repeating: 0) - SIMD4(repeating: 0) // expected-error{{'-' is unavailable: integer vector types do not support checked arithmetic; use the wrapping operator '&-' instead}} +let c = SIMD4(repeating: 0) * SIMD4(repeating: 0) // expected-error{{'*' is unavailable: integer vector types do not support checked arithmetic; use the wrapping operator '&*' instead}} +let x = SIMD4(repeating: 0) * (0 as Int32) // expected-error{{'*' is unavailable: integer vector types do not support checked arithmetic; use the wrapping operator '&*' instead}} +let y = (0 as Int32) * SIMD4(repeating: 0) // expected-error{{'*' is unavailable: integer vector types do not support checked arithmetic; use the wrapping operator '&*' instead}} -var d = int4(0) -d += int4(0) // expected-error{{'+=' is unavailable: integer vector types do not support checked arithmetic; use the wrapping operator '&+=' instead}} -d -= int4(0) // expected-error{{'-=' is unavailable: integer vector types do not support checked arithmetic; use the wrapping operator '&-=' instead}} -d *= int4(0) // expected-error{{'*=' is unavailable: integer vector types do not support checked arithmetic; use the wrapping operator '&*=' instead}} +var d = SIMD4(repeating: 0) +d += SIMD4(repeating: 0) // expected-error{{'+=' is unavailable: integer vector types do not support checked arithmetic; use the wrapping operator '&+=' instead}} +d -= SIMD4(repeating: 0) // expected-error{{'-=' is unavailable: integer vector types do not support checked arithmetic; use the wrapping operator '&-=' instead}} +d *= SIMD4(repeating: 0) // expected-error{{'*=' is unavailable: integer vector types do not support checked arithmetic; use the wrapping operator '&*=' instead}} d *= 0 // expected-error{{'*=' is unavailable: integer vector types do not support checked arithmetic; use the wrapping operator '&*=' instead}} diff --git a/validation-test/StdlibUnittest/CrashingTests.swift b/validation-test/StdlibUnittest/CrashingTests.swift index 8520f18ef85b6..fb69925921318 100644 --- a/validation-test/StdlibUnittest/CrashingTests.swift +++ b/validation-test/StdlibUnittest/CrashingTests.swift @@ -26,7 +26,7 @@ private func fatalErrorWithDelayIfNeeded( #if os(Windows) Sleep(1) #endif - fatalError(message, file: file, line: line) + fatalError(message(), file: file, line: line) } // diff --git a/validation-test/stdlib/Collection/LazyMapBidirectionalCollection.swift b/validation-test/stdlib/Collection/LazyMapBidirectionalCollection.swift index ff1019b6ebb1d..74165a82aa809 100644 --- a/validation-test/stdlib/Collection/LazyMapBidirectionalCollection.swift +++ b/validation-test/stdlib/Collection/LazyMapBidirectionalCollection.swift @@ -18,12 +18,12 @@ var CollectionTests = TestSuite("Collection") // Test collections using value types as elements. CollectionTests.addBidirectionalCollectionTests( - makeCollection: { (elements: [OpaqueValue]) -> LazyMapBidirectionalCollection>, OpaqueValue> in + makeCollection: { (elements: [OpaqueValue]) -> LazyMapCollection>, OpaqueValue> in MinimalBidirectionalCollection(elements: elements).lazy.map(identity) }, wrapValue: identity, extractValue: identity, - makeCollectionOfEquatable: { (elements: [MinimalEquatableValue]) -> LazyMapBidirectionalCollection, MinimalEquatableValue> in + makeCollectionOfEquatable: { (elements: [MinimalEquatableValue]) -> LazyMapCollection, MinimalEquatableValue> in MinimalBidirectionalCollection(elements: elements).lazy.map(identityEq) }, wrapValueIntoEquatable: identityEq, @@ -32,7 +32,7 @@ CollectionTests.addBidirectionalCollectionTests( // Test collections using reference types as elements. CollectionTests.addBidirectionalCollectionTests( - makeCollection: { (elements: [LifetimeTracked]) -> LazyMapBidirectionalCollection, LifetimeTracked> in + makeCollection: { (elements: [LifetimeTracked]) -> LazyMapCollection, LifetimeTracked> in MinimalBidirectionalCollection(elements: elements).lazy.map { $0 } }, wrapValue: { (element: OpaqueValue) in @@ -41,7 +41,7 @@ CollectionTests.addBidirectionalCollectionTests( extractValue: { (element: LifetimeTracked) in OpaqueValue(element.value, identity: element.identity) }, - makeCollectionOfEquatable: { (elements: [LifetimeTracked]) -> LazyMapBidirectionalCollection, LifetimeTracked> in + makeCollectionOfEquatable: { (elements: [LifetimeTracked]) -> LazyMapCollection, LifetimeTracked> in MinimalBidirectionalCollection(elements: elements).lazy.map { $0 } }, wrapValueIntoEquatable: { (element: MinimalEquatableValue) in diff --git a/validation-test/stdlib/Collection/LazyMapRandomAccessCollection.swift b/validation-test/stdlib/Collection/LazyMapRandomAccessCollection.swift index 7c535c163a43d..73b26fcbc7c72 100644 --- a/validation-test/stdlib/Collection/LazyMapRandomAccessCollection.swift +++ b/validation-test/stdlib/Collection/LazyMapRandomAccessCollection.swift @@ -18,12 +18,12 @@ var CollectionTests = TestSuite("Collection") // Test collections using value types as elements. CollectionTests.addRandomAccessCollectionTests( - makeCollection: { (elements: [OpaqueValue]) -> LazyMapRandomAccessCollection>, OpaqueValue> in + makeCollection: { (elements: [OpaqueValue]) -> LazyMapCollection>, OpaqueValue> in MinimalRandomAccessCollection(elements: elements).lazy.map(identity) }, wrapValue: identity, extractValue: identity, - makeCollectionOfEquatable: { (elements: [MinimalEquatableValue]) -> LazyMapRandomAccessCollection, MinimalEquatableValue> in + makeCollectionOfEquatable: { (elements: [MinimalEquatableValue]) -> LazyMapCollection, MinimalEquatableValue> in MinimalRandomAccessCollection(elements: elements).lazy.map(identityEq) }, wrapValueIntoEquatable: identityEq, @@ -32,7 +32,7 @@ CollectionTests.addRandomAccessCollectionTests( // Test collections using reference types as elements. CollectionTests.addRandomAccessCollectionTests( - makeCollection: { (elements: [LifetimeTracked]) -> LazyMapRandomAccessCollection, LifetimeTracked> in + makeCollection: { (elements: [LifetimeTracked]) -> LazyMapCollection, LifetimeTracked> in MinimalRandomAccessCollection(elements: elements).lazy.map { $0 } }, wrapValue: { (element: OpaqueValue) in @@ -41,7 +41,7 @@ CollectionTests.addRandomAccessCollectionTests( extractValue: { (element: LifetimeTracked) in OpaqueValue(element.value, identity: element.identity) }, - makeCollectionOfEquatable: { (elements: [LifetimeTracked]) -> LazyMapRandomAccessCollection, LifetimeTracked> in + makeCollectionOfEquatable: { (elements: [LifetimeTracked]) -> LazyMapCollection, LifetimeTracked> in MinimalRandomAccessCollection(elements: elements).lazy.map { $0 } }, wrapValueIntoEquatable: { (element: MinimalEquatableValue) in diff --git a/validation-test/stdlib/CollectionDiagnostics.swift b/validation-test/stdlib/CollectionDiagnostics.swift index 55fc2ee11e6f5..c784d4af1acec 100644 --- a/validation-test/stdlib/CollectionDiagnostics.swift +++ b/validation-test/stdlib/CollectionDiagnostics.swift @@ -48,9 +48,8 @@ func sortResultIgnored< array.sorted { $0 < $1 } // expected-warning {{result of call to 'sorted(by:)' is unused}} } -// expected-warning@+2 {{'Indexable' is deprecated: renamed to 'Collection'}} -// expected-note@+1 {{use 'Collection' instead}} -struct GoodIndexable : Indexable { +// expected-error@+1 {{'Indexable' has been renamed to 'Collection'}} +struct GoodIndexable : Indexable { func index(after i: Int) -> Int { return i + 1 } var startIndex: Int { return 0 } var endIndex: Int { return 0 } @@ -60,8 +59,7 @@ struct GoodIndexable : Indexable { } -// expected-warning@+2 {{'Indexable' is deprecated: renamed to 'Collection'}} -// expected-note@+1 {{use 'Collection' instead}} +// expected-error@+1 {{'Indexable' has been renamed to 'Collection'}} struct AnotherGoodIndexable1 : Indexable { func index(after i: Int) -> Int { return i + 1 } var startIndex: Int { return 0 } @@ -70,9 +68,8 @@ struct AnotherGoodIndexable1 : Indexable { subscript(pos: Int) -> Int { return 0 } } -// expected-warning@+3 {{'Indexable' is deprecated: renamed to 'Collection'}} -// expected-error@+2 {{type 'BadIndexable2' does not conform to protocol 'Collection'}} -// expected-note@+1 {{use 'Collection' instead}} +// expected-error@+2 {{'Indexable' has been renamed to 'Collection'}} +// expected-error@+1 {{type 'BadIndexable2' does not conform to protocol 'Collection'}} struct BadIndexable2 : Indexable { var startIndex: Int { return 0 } var endIndex: Int { return 0 } @@ -82,8 +79,7 @@ struct BadIndexable2 : Indexable { // Missing index(after:) -> Int } -// expected-warning@+2 {{'BidirectionalIndexable' is deprecated: renamed to 'BidirectionalCollection'}} -// expected-note@+1 {{use 'BidirectionalCollection' instead}} +// expected-error@+1 {{'BidirectionalIndexable' has been renamed to 'BidirectionalCollection'}} struct GoodBidirectionalIndexable1 : BidirectionalIndexable { var startIndex: Int { return 0 } var endIndex: Int { return 0 } @@ -96,8 +92,7 @@ struct GoodBidirectionalIndexable1 : BidirectionalIndexable { // We'd like to see: {{type 'BadBidirectionalIndexable' does not conform to protocol 'BidirectionalIndexable'}} // But the compiler doesn't generate that error. -// expected-warning@+2 {{'BidirectionalIndexable' is deprecated: renamed to 'BidirectionalCollection'}} -// expected-note@+1 {{use 'BidirectionalCollection' instead}} +// expected-error@+1 {{'BidirectionalIndexable' has been renamed to 'BidirectionalCollection'}} struct BadBidirectionalIndexable : BidirectionalIndexable { var startIndex: Int { return 0 } var endIndex: Int { return 0 } diff --git a/validation-test/stdlib/HashingAvalanche.swift b/validation-test/stdlib/HashingAvalanche.swift index bf9dd0d668022..06984445f9ea3 100644 --- a/validation-test/stdlib/HashingAvalanche.swift +++ b/validation-test/stdlib/HashingAvalanche.swift @@ -22,7 +22,7 @@ func avalancheTest( for inputBit in 0...allocate(capacity: Output.bitWidth) - bitFlips.initialize(to: 0, count: Output.bitWidth) + bitFlips.initialize(repeating: 0, count: Output.bitWidth) for i in testData.indices { let inputA = testData[i] let outputA = testDataHashed[i] diff --git a/validation-test/stdlib/Lazy.swift.gyb b/validation-test/stdlib/Lazy.swift.gyb index a65f00213ce85..0007a7b77822b 100644 --- a/validation-test/stdlib/Lazy.swift.gyb +++ b/validation-test/stdlib/Lazy.swift.gyb @@ -78,7 +78,7 @@ LazyTestSuite.test("Repeated") // Check that the generic parameter is called 'Element'. // FIXME: this should be extension CollectionOfOne.Iterator, but this needs // a fix to the compiler. -extension IteratorOverOne where Element : TestProtocol1 { +extension CollectionOfOne.Iterator where Element : TestProtocol1 { var _elementIsTestProtocol1: Bool { fatalError("not implemented") } @@ -368,7 +368,7 @@ LazyTestSuite.test("EmptyCollection/_failEarlyRangeCheck/NoTrap") { //===----------------------------------------------------------------------===// // Check that the generic parameter is called 'Element'. -extension EmptyIterator where Element : TestProtocol1 { +extension EmptyCollection.Iterator where Element : TestProtocol1 { var _elementIsTestProtocol1: Bool { fatalError("not implemented") } @@ -552,7 +552,7 @@ LazyTestSuite.test("Lazy${TraversalCollection}.array") { LazyTestSuite.test("Lazy${TraversalCollection}.reversed") { let base = Minimal${TraversalCollection}( elements: [ 0, 30, 10, 90 ].map(OpaqueValue.init), - underestimatedCount: .value(42)) + underestimatedCount: .value(4)) var reversed = base.lazy.reversed() expectType( ${ReversedType}> >>>.self, &reversedTwice) +#else + // Reversing twice gets back the original collection in Swift 5+ + expectType( + LazyCollection>>.self, + &reversedTwice) +#endif check${Traversal}Collection( [ 0, 30, 10, 90 ].map(OpaqueValue.init) as [OpaqueValue], diff --git a/validation-test/stdlib/Range.swift.gyb b/validation-test/stdlib/Range.swift.gyb index b8fa3838e0f7f..9d6585bc91e39 100644 --- a/validation-test/stdlib/Range.swift.gyb +++ b/validation-test/stdlib/Range.swift.gyb @@ -313,27 +313,27 @@ let indexDistanceTests: [IndexDistanceTest] = [ %{ all_range_types = [ - ('Range', '..<', 'MinimalComparableValue', ''), - ('Range', '..<', 'MinimalStrideableValue', 'Countable'), - ('ClosedRange', '...', 'MinimalComparableValue', ''), - ('ClosedRange', '...', 'MinimalStrideableValue', 'Countable'), + ('Range', '..<', 'MinimalComparableValue'), + ('ClosedRange', '...', 'MinimalComparableValue'), ] }% -% for (Self, op, Bound, Countable) in all_range_types: -% TestSuite = Countable + Self + 'TestSuite' +% for (Self, op, Bound) in all_range_types: +% TestSuite = Self + 'TestSuite' -% if Countable == '': // Check that the generic parameter is called 'Bound'. extension ${Self} where Bound : TestProtocol1 { var _elementIsTestProtocol1: Bool { fatalError("not implemented") } } -% end var ${TestSuite} = TestSuite("${Self}") +${TestSuite}.test("countable") { + expectEqualType(${Self}.self, Countable${Self}.self) +} + ${TestSuite}.test("init(uncheckedBounds:)") .forEach(in: [(1, 2), (1, 1), (2, 1)]) { (lowerInt, upperInt) in @@ -346,7 +346,8 @@ ${TestSuite}.test("init(uncheckedBounds:)") expectEqual(upperInt, r.upperBound.value) } -% for (DestinationSelf, _, _, _) in all_range_types: +% for (DestinationSelf, _, _) in all_range_types: +% if DestinationSelf != Self: ${TestSuite}.test("init(${DestinationSelf})/whereBoundIsStrideable") .forEach(in: [(0, 0), (1, 2), (10, 20), (Int.min, Int.max)]) { (lowerInt, upperInt) in @@ -367,7 +368,6 @@ ${TestSuite}.test("init(${DestinationSelf})/whereBoundIsStrideable") } let converted = ${DestinationSelf}(source) - if !shouldTrap { expectEqual(lower.value, converted.lowerBound.value) expectEqual( @@ -375,6 +375,7 @@ ${TestSuite}.test("init(${DestinationSelf})/whereBoundIsStrideable") converted.upperBound.value) } } +% end % end ${TestSuite}.test("lowerBound, upperBound") { @@ -489,7 +490,7 @@ ${TestSuite}.test("contains(_:)/semantics, ~=/semantics") expectEqual(expected, range ~= value) } -% for (OtherSelf, other_op, OtherBound, __elementIsTestProtocol1) in all_range_types: +% for (OtherSelf, other_op, OtherBound) in all_range_types: ${TestSuite}.test("overlaps(${OtherSelf})/semantics") .forEach(in: overlapsTests) { (test) in @@ -728,7 +729,7 @@ ${TestSuite}.test("isEmpty") { } ${TestSuite}.test("CustomStringConvertible, CustomDebugStringConvertible, CustomReflectable") { - var r: ${Self} = + let r: ${Self} = CustomPrintableValue(1)${op}CustomPrintableValue(2) expectPrinted("(value: 1).description${op}(value: 2).description", r) expectDebugPrinted( @@ -749,7 +750,7 @@ ${TestSuite}.test("CustomStringConvertible, CustomDebugStringConvertible, Custom % end -CountableRangeTestSuite.test("AssociatedTypes") { +RangeTestSuite.test("AssociatedTypes") { typealias Collection = Range expectCollectionAssociatedTypes( collectionType: Collection.self, @@ -759,7 +760,7 @@ CountableRangeTestSuite.test("AssociatedTypes") { indicesType: Collection.self) } -CountableClosedRangeTestSuite.test("AssociatedTypes") { +ClosedRangeTestSuite.test("AssociatedTypes") { typealias Collection = ClosedRange expectCollectionAssociatedTypes( collectionType: Collection.self,