mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Remove Swift 3-specific tests
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
// RUN: not %target-swift-frontend -typecheck -verify -I %S/Inputs/custom-modules -F %S/Inputs/custom-frameworks -swift-version 3 %s
|
||||
// RUN: %target-swift-frontend -typecheck -verify -I %S/Inputs/custom-modules -F %S/Inputs/custom-frameworks -swift-version 4.2 %s
|
||||
// RUN: %target-swift-frontend -typecheck -verify -I %S/Inputs/custom-modules -F %S/Inputs/custom-frameworks -swift-version 5 %s
|
||||
// REQUIRES: objc_interop
|
||||
|
||||
@@ -1,112 +1,11 @@
|
||||
// RUN: %empty-directory(%t)
|
||||
|
||||
// RUN: %target-swift-ide-test -F %S/Inputs/custom-frameworks -print-module -source-filename %s -module-to-print=APINotesFrameworkTest -function-definitions=false -print-regular-comments -swift-version 3 | %FileCheck -check-prefix=CHECK-SWIFT-3 %s
|
||||
|
||||
// RUN: %target-swift-ide-test -F %S/Inputs/custom-frameworks -print-module -source-filename %s -module-to-print=APINotesFrameworkTest -function-definitions=false -swift-version 4 | %FileCheck -check-prefix=CHECK-SWIFT-4 %s
|
||||
|
||||
// RUN: %target-swift-ide-test -F %S/Inputs/custom-frameworks -print-module -source-filename %s -module-to-print=APINotesFrameworkTest -function-definitions=false -swift-version 4.2 | %FileCheck -check-prefix=CHECK-SWIFT-4-2 %s
|
||||
|
||||
// RUN: %target-swift-ide-test -F %S/Inputs/custom-frameworks -print-module -source-filename %s -module-to-print=APINotesFrameworkTest -function-definitions=false -swift-version 5 | %FileCheck -check-prefix=CHECK-SWIFT-5 %s
|
||||
|
||||
// CHECK-SWIFT-3: @available(swift, obsoleted: 3, renamed: "multiVersionedGlobal4_4")
|
||||
// CHECK-SWIFT-3: var multiVersionedGlobal4: Int32
|
||||
// CHECK-SWIFT-3: var multiVersionedGlobal4_4: Int32
|
||||
// CHECK-SWIFT-3: @available(swift, obsoleted: 3, renamed: "multiVersionedGlobal4Notes_4")
|
||||
// CHECK-SWIFT-3: var multiVersionedGlobal4Notes: Int32
|
||||
// CHECK-SWIFT-3: var multiVersionedGlobal4Notes_4: Int32
|
||||
// CHECK-SWIFT-3: @available(swift, introduced: 5, renamed: "multiVersionedGlobal4Notes_4")
|
||||
// CHECK-SWIFT-3: var multiVersionedGlobal4Notes_NEW: Int32
|
||||
// CHECK-SWIFT-3: @available(swift, obsoleted: 3, renamed: "multiVersionedGlobal4Header_4")
|
||||
// CHECK-SWIFT-3: var multiVersionedGlobal4Header: Int32
|
||||
// CHECK-SWIFT-3: var multiVersionedGlobal4Header_4: Int32
|
||||
// CHECK-SWIFT-3: @available(swift, introduced: 5, renamed: "multiVersionedGlobal4Header_4")
|
||||
// CHECK-SWIFT-3: var multiVersionedGlobal4Header_NEW: Int32
|
||||
// CHECK-SWIFT-3: @available(swift, obsoleted: 3, renamed: "multiVersionedGlobal4Both_4")
|
||||
// CHECK-SWIFT-3: var multiVersionedGlobal4Both: Int32
|
||||
// CHECK-SWIFT-3: var multiVersionedGlobal4Both_4: Int32
|
||||
// CHECK-SWIFT-3: @available(swift, introduced: 5, renamed: "multiVersionedGlobal4Both_4")
|
||||
// CHECK-SWIFT-3: var multiVersionedGlobal4Both_NEW: Int32
|
||||
|
||||
// CHECK-SWIFT-3: @available(swift, obsoleted: 3, renamed: "multiVersionedGlobal34_3")
|
||||
// CHECK-SWIFT-3: var multiVersionedGlobal34: Int32
|
||||
// CHECK-SWIFT-3: var multiVersionedGlobal34_3: Int32
|
||||
// CHECK-SWIFT-3: @available(swift, introduced: 4, renamed: "multiVersionedGlobal34_3")
|
||||
// CHECK-SWIFT-3: var multiVersionedGlobal34_4: Int32
|
||||
// CHECK-SWIFT-3: @available(swift, obsoleted: 3, renamed: "multiVersionedGlobal34Notes_3")
|
||||
// CHECK-SWIFT-3: var multiVersionedGlobal34Notes: Int32
|
||||
// CHECK-SWIFT-3: var multiVersionedGlobal34Notes_3: Int32
|
||||
// CHECK-SWIFT-3: @available(swift, introduced: 4, renamed: "multiVersionedGlobal34Notes_3")
|
||||
// CHECK-SWIFT-3: var multiVersionedGlobal34Notes_4: Int32
|
||||
// CHECK-SWIFT-3: @available(swift, introduced: 5, renamed: "multiVersionedGlobal34Notes_3")
|
||||
// CHECK-SWIFT-3: var multiVersionedGlobal34Notes_NEW: Int32
|
||||
// CHECK-SWIFT-3: @available(swift, obsoleted: 3, renamed: "multiVersionedGlobal34Header_3")
|
||||
// CHECK-SWIFT-3: var multiVersionedGlobal34Header: Int32
|
||||
// CHECK-SWIFT-3: var multiVersionedGlobal34Header_3: Int32
|
||||
// CHECK-SWIFT-3: @available(swift, introduced: 4, renamed: "multiVersionedGlobal34Header_3")
|
||||
// CHECK-SWIFT-3: var multiVersionedGlobal34Header_4: Int32
|
||||
// CHECK-SWIFT-3: @available(swift, introduced: 5, renamed: "multiVersionedGlobal34Header_3")
|
||||
// CHECK-SWIFT-3: var multiVersionedGlobal34Header_NEW: Int32
|
||||
// CHECK-SWIFT-3: @available(swift, obsoleted: 3, renamed: "multiVersionedGlobal34Both_3")
|
||||
// CHECK-SWIFT-3: var multiVersionedGlobal34Both: Int32
|
||||
// CHECK-SWIFT-3: var multiVersionedGlobal34Both_3: Int32
|
||||
// CHECK-SWIFT-3: @available(swift, introduced: 4, renamed: "multiVersionedGlobal34Both_3")
|
||||
// CHECK-SWIFT-3: var multiVersionedGlobal34Both_4: Int32
|
||||
// CHECK-SWIFT-3: @available(swift, introduced: 5, renamed: "multiVersionedGlobal34Both_3")
|
||||
// CHECK-SWIFT-3: var multiVersionedGlobal34Both_NEW: Int32
|
||||
|
||||
// CHECK-SWIFT-3: @available(swift, obsoleted: 3, renamed: "multiVersionedGlobal45_4")
|
||||
// CHECK-SWIFT-3: var multiVersionedGlobal45: Int32
|
||||
// CHECK-SWIFT-3: var multiVersionedGlobal45_4: Int32
|
||||
// CHECK-SWIFT-3: @available(swift, introduced: 5, renamed: "multiVersionedGlobal45_4")
|
||||
// CHECK-SWIFT-3: var multiVersionedGlobal45_5: Int32
|
||||
// CHECK-SWIFT-3: @available(swift, obsoleted: 3, renamed: "multiVersionedGlobal45Notes_4")
|
||||
// CHECK-SWIFT-3: var multiVersionedGlobal45Notes: Int32
|
||||
// CHECK-SWIFT-3: var multiVersionedGlobal45Notes_4: Int32
|
||||
// CHECK-SWIFT-3: @available(swift, introduced: 5, renamed: "multiVersionedGlobal45Notes_4")
|
||||
// CHECK-SWIFT-3: var multiVersionedGlobal45Notes_5: Int32
|
||||
// CHECK-SWIFT-3: @available(swift, obsoleted: 3, renamed: "multiVersionedGlobal45Header_4")
|
||||
// CHECK-SWIFT-3: var multiVersionedGlobal45Header: Int32
|
||||
// CHECK-SWIFT-3: var multiVersionedGlobal45Header_4: Int32
|
||||
// CHECK-SWIFT-3: @available(swift, introduced: 5, renamed: "multiVersionedGlobal45Header_4")
|
||||
// CHECK-SWIFT-3: var multiVersionedGlobal45Header_5: Int32
|
||||
// CHECK-SWIFT-3: @available(swift, obsoleted: 3, renamed: "multiVersionedGlobal45Both_4")
|
||||
// CHECK-SWIFT-3: var multiVersionedGlobal45Both: Int32
|
||||
// CHECK-SWIFT-3: var multiVersionedGlobal45Both_4: Int32
|
||||
// CHECK-SWIFT-3: @available(swift, introduced: 5, renamed: "multiVersionedGlobal45Both_4")
|
||||
// CHECK-SWIFT-3: var multiVersionedGlobal45Both_5: Int32
|
||||
|
||||
// CHECK-SWIFT-3: @available(swift, obsoleted: 3, renamed: "multiVersionedGlobal345_3")
|
||||
// CHECK-SWIFT-3: var multiVersionedGlobal345: Int32
|
||||
// CHECK-SWIFT-3: var multiVersionedGlobal345_3: Int32
|
||||
// CHECK-SWIFT-3: @available(swift, introduced: 4, renamed: "multiVersionedGlobal345_3")
|
||||
// CHECK-SWIFT-3: var multiVersionedGlobal345_4: Int32
|
||||
// CHECK-SWIFT-3: @available(swift, introduced: 5, renamed: "multiVersionedGlobal345_3")
|
||||
// CHECK-SWIFT-3: var multiVersionedGlobal345_5: Int32
|
||||
// CHECK-SWIFT-3: @available(swift, obsoleted: 3, renamed: "multiVersionedGlobal345Notes_3")
|
||||
// CHECK-SWIFT-3: var multiVersionedGlobal345Notes: Int32
|
||||
// CHECK-SWIFT-3: var multiVersionedGlobal345Notes_3: Int32
|
||||
// CHECK-SWIFT-3: @available(swift, introduced: 4, renamed: "multiVersionedGlobal345Notes_3")
|
||||
// CHECK-SWIFT-3: var multiVersionedGlobal345Notes_4: Int32
|
||||
// CHECK-SWIFT-3: @available(swift, introduced: 5, renamed: "multiVersionedGlobal345Notes_3")
|
||||
// CHECK-SWIFT-3: var multiVersionedGlobal345Notes_5: Int32
|
||||
// CHECK-SWIFT-3: @available(swift, obsoleted: 3, renamed: "multiVersionedGlobal345Header_3")
|
||||
// CHECK-SWIFT-3: var multiVersionedGlobal345Header: Int32
|
||||
// CHECK-SWIFT-3: var multiVersionedGlobal345Header_3: Int32
|
||||
// CHECK-SWIFT-3: @available(swift, introduced: 4, renamed: "multiVersionedGlobal345Header_3")
|
||||
// CHECK-SWIFT-3: var multiVersionedGlobal345Header_4: Int32
|
||||
// CHECK-SWIFT-3: @available(swift, introduced: 5, renamed: "multiVersionedGlobal345Header_3")
|
||||
// CHECK-SWIFT-3: var multiVersionedGlobal345Header_5: Int32
|
||||
// CHECK-SWIFT-3: @available(swift, obsoleted: 3, renamed: "multiVersionedGlobal345Both_3")
|
||||
// CHECK-SWIFT-3: var multiVersionedGlobal345Both: Int32
|
||||
// CHECK-SWIFT-3: var multiVersionedGlobal345Both_3: Int32
|
||||
// CHECK-SWIFT-3: @available(swift, introduced: 4, renamed: "multiVersionedGlobal345Both_3")
|
||||
// CHECK-SWIFT-3: var multiVersionedGlobal345Both_4: Int32
|
||||
// CHECK-SWIFT-3: @available(swift, introduced: 5, renamed: "multiVersionedGlobal345Both_3")
|
||||
// CHECK-SWIFT-3: var multiVersionedGlobal345Both_5: Int32
|
||||
// CHECK-SWIFT-3: @available(swift, obsoleted: 3, renamed: "multiVersionedGlobal34_4_2_not_5")
|
||||
// CHECK-SWIFT-3: var multiVersionedGlobal34_4_2: Int32
|
||||
// CHECK-SWIFT-3: var multiVersionedGlobal34_4_2_not_5: Int32
|
||||
|
||||
|
||||
// CHECK-SWIFT-4: @available(swift, obsoleted: 3, renamed: "multiVersionedGlobal4_4")
|
||||
// CHECK-SWIFT-4: var multiVersionedGlobal4: Int32
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -typecheck -verify -I %S/Inputs/custom-modules -swift-version 3 -enable-nonfrozen-enum-exhaustivity-diagnostics %s
|
||||
|
||||
// REQUIRES: objc_interop
|
||||
|
||||
import Foundation
|
||||
import AvailabilityExtras
|
||||
|
||||
func exhaustiveSwitch(e: NSEnumAddedCasesIn2017) {
|
||||
switch e { // expected-warning{{switch must be exhaustive}}
|
||||
// expected-note@-1{{add missing case: '.newCaseOne'}}
|
||||
// expected-note@-2{{handle unknown values using "@unknown default"}}
|
||||
case .existingCaseOne:
|
||||
return
|
||||
case .existingCaseTwo:
|
||||
return
|
||||
case .existingCaseThree:
|
||||
return
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,4 @@
|
||||
// RUN: not %target-swift-frontend -swift-version 3 -typecheck %s 2> %t.3.txt
|
||||
// RUN: %FileCheck -check-prefix=CHECK-3 -check-prefix=CHECK-%target-runtime-3 %s < %t.3.txt
|
||||
// RUN: not %target-swift-frontend -swift-version 4 -typecheck %s 2> %t.4.txt
|
||||
// RUN: %FileCheck -check-prefix=CHECK-4 -check-prefix=CHECK-%target-runtime-4 %s < %t.4.txt
|
||||
// RUN: not %target-swift-frontend -swift-version 4 -typecheck %s 2>&1 | %FileCheck -check-prefix=CHECK -check-prefix=CHECK-%target-runtime %s
|
||||
|
||||
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
|
||||
import Darwin
|
||||
@@ -13,20 +10,16 @@
|
||||
|
||||
func test() {
|
||||
let _: Int = strxfrm
|
||||
// CHECK-3: [[@LINE-1]]:16: error: cannot convert value of type '({{.+}}) -> UInt'{{( [(]aka .+[)])?}} to specified type 'Int'
|
||||
// CHECK-4: [[@LINE-2]]:16: error: cannot convert value of type '({{.+}}) -> Int'{{( [(]aka .+[)])?}} to specified type 'Int'
|
||||
// CHECK: [[@LINE-1]]:16: error: cannot convert value of type '({{.+}}) -> Int'{{( [(]aka .+[)])?}} to specified type 'Int'
|
||||
|
||||
let _: Int = strcspn
|
||||
// CHECK-3: [[@LINE-1]]:16: error: cannot convert value of type '({{.+}}) -> UInt'{{( [(]aka .+[)])?}} to specified type 'Int'
|
||||
// CHECK-4: [[@LINE-2]]:16: error: cannot convert value of type '({{.+}}) -> Int'{{( [(]aka .+[)])?}} to specified type 'Int'
|
||||
// CHECK: [[@LINE-1]]:16: error: cannot convert value of type '({{.+}}) -> Int'{{( [(]aka .+[)])?}} to specified type 'Int'
|
||||
|
||||
let _: Int = strspn
|
||||
// CHECK-3: [[@LINE-1]]:16: error: cannot convert value of type '({{.+}}) -> UInt'{{( [(]aka .+[)])?}} to specified type 'Int'
|
||||
// CHECK-4: [[@LINE-2]]:16: error: cannot convert value of type '({{.+}}) -> Int'{{( [(]aka .+[)])?}} to specified type 'Int'
|
||||
// CHECK: [[@LINE-1]]:16: error: cannot convert value of type '({{.+}}) -> Int'{{( [(]aka .+[)])?}} to specified type 'Int'
|
||||
|
||||
let _: Int = strlen
|
||||
// CHECK-3: [[@LINE-1]]:16: error: cannot convert value of type '({{.+}}) -> UInt'{{( [(]aka .+[)])?}} to specified type 'Int'
|
||||
// CHECK-4: [[@LINE-2]]:16: error: cannot convert value of type '({{.+}}) -> Int'{{( [(]aka .+[)])?}} to specified type 'Int'
|
||||
// CHECK: [[@LINE-1]]:16: error: cannot convert value of type '({{.+}}) -> Int'{{( [(]aka .+[)])?}} to specified type 'Int'
|
||||
}
|
||||
|
||||
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
|
||||
@@ -34,17 +27,14 @@ func test() {
|
||||
// test for them on Apple platforms.
|
||||
func testApple() {
|
||||
let _: Int = strlcpy
|
||||
// CHECK-objc-3: [[@LINE-1]]:16: error: cannot convert value of type '({{.+}}) -> UInt'{{( [(]aka .+[)])?}} to specified type 'Int'
|
||||
// CHECK-objc-4: [[@LINE-2]]:16: error: cannot convert value of type '({{.+}}) -> Int'{{( [(]aka .+[)])?}} to specified type 'Int'
|
||||
// CHECK-objc: [[@LINE-1]]:16: error: cannot convert value of type '({{.+}}) -> Int'{{( [(]aka .+[)])?}} to specified type 'Int'
|
||||
|
||||
let _: Int = strlcat
|
||||
// CHECK-objc-3: [[@LINE-1]]:16: error: cannot convert value of type '({{.+}}) -> UInt'{{( [(]aka .+[)])?}} to specified type 'Int'
|
||||
// CHECK-objc-4: [[@LINE-2]]:16: error: cannot convert value of type '({{.+}}) -> Int'{{( [(]aka .+[)])?}} to specified type 'Int'
|
||||
// CHECK-objc: [[@LINE-1]]:16: error: cannot convert value of type '({{.+}}) -> Int'{{( [(]aka .+[)])?}} to specified type 'Int'
|
||||
|
||||
// wcslen is different: it wasn't a builtin until Swift 4, and so its return
|
||||
// type has always been 'Int'.
|
||||
let _: Int = wcslen
|
||||
// CHECK-objc-3: [[@LINE-1]]:16: error: cannot convert value of type '({{.+}}) -> Int'{{( [(]aka .+[)])?}} to specified type 'Int'
|
||||
// CHECK-objc-4: [[@LINE-2]]:16: error: cannot convert value of type '({{.+}}) -> Int'{{( [(]aka .+[)])?}} to specified type 'Int'
|
||||
// CHECK-objc: [[@LINE-1]]:16: error: cannot convert value of type '({{.+}}) -> Int'{{( [(]aka .+[)])?}} to specified type 'Int'
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -1,27 +0,0 @@
|
||||
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -typecheck -parse-as-library -verify -swift-version 3 %s
|
||||
|
||||
// REQUIRES: objc_interop
|
||||
|
||||
import Foundation
|
||||
import objc_generics
|
||||
|
||||
// Test type-erased bounds
|
||||
|
||||
func getContainerForPanda() -> AnimalContainer<Animal> {
|
||||
return Panda.getContainer()
|
||||
}
|
||||
|
||||
// Note that in Swift 3, there's basically no way to call the
|
||||
// Panda.getFungibleContainer() method, because it is imported
|
||||
// with a malformed type.
|
||||
|
||||
// expected-error@+1 {{type 'Animal' does not conform to protocol 'Fungible'}}
|
||||
func getContainerForFungiblePanda() -> FungibleAnimalContainer<Animal> {
|
||||
return Panda.getFungibleContainer()
|
||||
}
|
||||
|
||||
|
||||
func getContainerForFungiblePanda() -> FungibleAnimalContainer<Animal & Fungible> {
|
||||
// expected-error@+1 {{cannot convert return expression of type 'FungibleAnimalContainer<Animal>?' to return type 'FungibleAnimalContainer<Animal & Fungible>'}}
|
||||
return Panda.getFungibleContainer()
|
||||
}
|
||||
@@ -1,5 +1,4 @@
|
||||
// RUN: %target-swift-frontend -swift-version 3 -typecheck %s -enable-objc-interop -import-objc-header %S/Inputs/objc_curried_method.h
|
||||
// RUN: %target-swift-frontend -swift-version 4 -typecheck %s -enable-objc-interop -import-objc-header %S/Inputs/objc_curried_method.h
|
||||
// RUN: %target-swift-frontend -typecheck %s -enable-objc-interop -import-objc-header %S/Inputs/objc_curried_method.h
|
||||
|
||||
// rdar://problem/32588152
|
||||
|
||||
|
||||
@@ -1,45 +0,0 @@
|
||||
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -typecheck -verify -o - -primary-file %s -swift-version 3 -I %S/Inputs/custom-modules/
|
||||
|
||||
// REQUIRES: objc_interop
|
||||
|
||||
import Foundation
|
||||
import SubclassExistentialsExtra
|
||||
|
||||
// FIXME: Consider better diagnostics here.
|
||||
|
||||
class SwiftLaundryService : NSLaundry {
|
||||
// expected-error@-1 {{type 'SwiftLaundryService' does not conform to protocol 'NSLaundry'}}
|
||||
var g: (Garment & Coat)? = nil
|
||||
|
||||
func wash(_ g: Garment & Coat) { // expected-note {{candidate has non-matching type '(Coat & Garment) -> ()'}}
|
||||
self.g = g
|
||||
}
|
||||
|
||||
func bleach(_ g: Garment & Coat & Cotton) {} // expected-note {{candidate has non-matching type '(Coat & Cotton & Garment) -> ()'}}
|
||||
|
||||
func dry() -> Garment & Coat { // expected-note {{candidate has non-matching type '() -> Coat & Garment'}}
|
||||
return g!
|
||||
}
|
||||
}
|
||||
|
||||
class OldSwiftLaundryService : NSLaundry {
|
||||
var g: Coat? = nil
|
||||
|
||||
func wash(_ g: Coat) {
|
||||
self.g = g
|
||||
}
|
||||
|
||||
func bleach(_ g: Coat) {}
|
||||
|
||||
func dry() -> Coat {
|
||||
return g!
|
||||
}
|
||||
}
|
||||
|
||||
func testInheritanceFromComposition(_ object: CompositionSubObject, _ specific: CompositionSubSpecific) {
|
||||
let _: NSObject = object
|
||||
let _: NSCopying = object
|
||||
|
||||
let _: SomeSpecificSubclass = specific
|
||||
let _: NSCopying = specific
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
// RUN: %target-typecheck-verify-swift -swift-version 3
|
||||
|
||||
public struct Pair<A, B> {}
|
||||
|
||||
public struct PublicStruct {
|
||||
public struct Inner {}
|
||||
internal struct Internal {}
|
||||
}
|
||||
|
||||
private typealias PrivateAlias = PublicStruct // expected-note * {{type declared here}}
|
||||
|
||||
public let a0 = nil as PrivateAlias.Inner? // expected-warning {{constant should not be declared public because its type 'PrivateAlias.Inner?' (aka 'Optional<PublicStruct.Inner>') uses a private type}}
|
||||
public let a: PrivateAlias.Inner? // expected-warning {{constant should not be declared public because its type uses a private type}}
|
||||
public let b: PrivateAlias.Internal? // expected-error {{constant cannot be declared public because its type uses an internal type}}
|
||||
public let c: Pair<PrivateAlias.Inner, PublicStruct.Internal>? // expected-error {{constant cannot be declared public because its type uses an internal type}}
|
||||
public let c2: Pair<PublicStruct.Internal, PrivateAlias.Inner>? // expected-error {{constant cannot be declared public because its type uses an internal type}}
|
||||
public let d: PrivateAlias? // expected-error {{constant cannot be declared public because its type uses a private type}}
|
||||
|
||||
|
||||
// rdar://problem/21408035
|
||||
private class PrivateBox<T> { // expected-note * {{type declared here}}
|
||||
typealias ValueType = T
|
||||
typealias AlwaysFloat = Float
|
||||
}
|
||||
|
||||
let boxUnboxInt: PrivateBox<Int>.ValueType = 0 // expected-warning {{constant should be declared private because its type uses a private type}}
|
||||
let boxFloat: PrivateBox<Int>.AlwaysFloat = 0 // expected-error {{constant must be declared private or fileprivate because its type uses a private type}}
|
||||
|
||||
private protocol PrivateProto {
|
||||
associatedtype Inner
|
||||
}
|
||||
extension PublicStruct: PrivateProto {}
|
||||
|
||||
private class SpecificBox<T: PrivateProto> { // expected-note * {{type declared here}}
|
||||
typealias InnerType = T.Inner
|
||||
typealias AlwaysFloat = Float
|
||||
}
|
||||
|
||||
let specificBoxUnboxInt: SpecificBox<PublicStruct>.InnerType = .init() // expected-warning {{constant should be declared private because its type uses a private type}}
|
||||
let specificBoxFloat: SpecificBox<PublicStruct>.AlwaysFloat = 0 // expected-error {{constant must be declared private or fileprivate because its type uses a private type}}
|
||||
|
||||
@@ -1,218 +0,0 @@
|
||||
// RUN: %target-typecheck-verify-swift -swift-version 3
|
||||
|
||||
class Container {
|
||||
private func foo() {} // expected-note * {{declared here}}
|
||||
private var bar = 0 // expected-note * {{declared here}}
|
||||
|
||||
private struct PrivateInner {} // expected-note * {{declared here}}
|
||||
|
||||
func localTest() {
|
||||
foo()
|
||||
self.foo()
|
||||
|
||||
_ = bar
|
||||
bar = 5
|
||||
_ = self.bar
|
||||
self.bar = 5
|
||||
|
||||
privateExtensionMethod() // expected-error {{'privateExtensionMethod' is inaccessible due to 'private' protection level}}
|
||||
self.privateExtensionMethod() // expected-error {{'privateExtensionMethod' is inaccessible due to 'private' protection level}}
|
||||
|
||||
_ = PrivateInner()
|
||||
_ = Container.PrivateInner()
|
||||
}
|
||||
|
||||
struct Inner {
|
||||
func test(obj: Container) {
|
||||
obj.foo()
|
||||
_ = obj.bar
|
||||
obj.bar = 5
|
||||
obj.privateExtensionMethod() // expected-error {{'privateExtensionMethod' is inaccessible due to 'private' protection level}}
|
||||
|
||||
_ = PrivateInner()
|
||||
_ = Container.PrivateInner()
|
||||
}
|
||||
|
||||
var inner: PrivateInner? // expected-error {{property must be declared private because its type uses a private type}}
|
||||
var innerQualified: Container.PrivateInner? // expected-error {{property must be declared private because its type uses a private type}}
|
||||
}
|
||||
|
||||
var inner: PrivateInner? // expected-error {{property must be declared private because its type uses a private type}}
|
||||
var innerQualified: Container.PrivateInner? // expected-error {{property must be declared private because its type uses a private type}}
|
||||
}
|
||||
|
||||
func test(obj: Container) {
|
||||
obj.foo() // expected-error {{'foo' is inaccessible due to 'private' protection level}}
|
||||
_ = obj.bar // expected-error {{'bar' is inaccessible due to 'private' protection level}}
|
||||
obj.bar = 5 // expected-error {{'bar' is inaccessible due to 'private' protection level}}
|
||||
obj.privateExtensionMethod() // expected-error {{'privateExtensionMethod' is inaccessible due to 'private' protection level}}
|
||||
|
||||
_ = Container.PrivateInner() // expected-error {{'PrivateInner' is inaccessible due to 'private' protection level}}
|
||||
}
|
||||
|
||||
extension Container {
|
||||
private func privateExtensionMethod() {} // expected-note * {{declared here}}
|
||||
|
||||
func extensionTest() {
|
||||
foo() // expected-error {{'foo' is inaccessible due to 'private' protection level}}
|
||||
self.foo() // expected-error {{'foo' is inaccessible due to 'private' protection level}}
|
||||
|
||||
_ = bar // expected-error {{'bar' is inaccessible due to 'private' protection level}}
|
||||
bar = 5 // expected-error {{'bar' is inaccessible due to 'private' protection level}}
|
||||
_ = self.bar // expected-error {{'bar' is inaccessible due to 'private' protection level}}
|
||||
self.bar = 5 // expected-error {{'bar' is inaccessible due to 'private' protection level}}
|
||||
|
||||
privateExtensionMethod()
|
||||
self.privateExtensionMethod()
|
||||
|
||||
_ = PrivateInner() // expected-error {{'PrivateInner' is inaccessible due to 'private' protection level}}
|
||||
_ = Container.PrivateInner() // expected-error {{'PrivateInner' is inaccessible due to 'private' protection level}}
|
||||
}
|
||||
|
||||
var extensionInner: PrivateInner? { return nil } // expected-error {{'PrivateInner' is inaccessible due to 'private' protection level}}
|
||||
var extensionInnerQualified: Container.PrivateInner? { return nil } // expected-error {{'PrivateInner' is inaccessible due to 'private' protection level}}
|
||||
}
|
||||
|
||||
extension Container.Inner {
|
||||
func extensionTest(obj: Container) {
|
||||
obj.foo() // expected-error {{'foo' is inaccessible due to 'private' protection level}}
|
||||
_ = obj.bar // expected-error {{'bar' is inaccessible due to 'private' protection level}}
|
||||
obj.bar = 5 // expected-error {{'bar' is inaccessible due to 'private' protection level}}
|
||||
obj.privateExtensionMethod() // expected-error {{'privateExtensionMethod' is inaccessible due to 'private' protection level}}
|
||||
|
||||
// FIXME: Unqualified lookup won't look into Container from here.
|
||||
_ = PrivateInner() // expected-error {{use of unresolved identifier 'PrivateInner'}}
|
||||
_ = Container.PrivateInner() // expected-error {{'PrivateInner' is inaccessible due to 'private' protection level}}
|
||||
}
|
||||
|
||||
// FIXME: Unqualified lookup won't look into Container from here.
|
||||
var inner: PrivateInner? { return nil } // expected-error {{use of undeclared type 'PrivateInner'}}
|
||||
var innerQualified: Container.PrivateInner? { return nil } // expected-error {{'PrivateInner' is inaccessible due to 'private' protection level}}
|
||||
}
|
||||
|
||||
class Sub : Container {
|
||||
func subTest() {
|
||||
foo() // expected-error {{'foo' is inaccessible due to 'private' protection level}}
|
||||
self.foo() // expected-error {{'foo' is inaccessible due to 'private' protection level}}
|
||||
|
||||
_ = bar // expected-error {{'bar' is inaccessible due to 'private' protection level}}
|
||||
bar = 5 // expected-error {{'bar' is inaccessible due to 'private' protection level}}
|
||||
_ = self.bar // expected-error {{'bar' is inaccessible due to 'private' protection level}}
|
||||
self.bar = 5 // expected-error {{'bar' is inaccessible due to 'private' protection level}}
|
||||
|
||||
privateExtensionMethod() // expected-error {{'privateExtensionMethod' is inaccessible due to 'private' protection level}}
|
||||
self.privateExtensionMethod() // expected-error {{'privateExtensionMethod' is inaccessible due to 'private' protection level}}
|
||||
|
||||
_ = PrivateInner() // expected-error {{'PrivateInner' is inaccessible due to 'private' protection level}}
|
||||
_ = Container.PrivateInner() // expected-error {{'PrivateInner' is inaccessible due to 'private' protection level}}
|
||||
}
|
||||
|
||||
var subInner: PrivateInner? // expected-error {{'PrivateInner' is inaccessible due to 'private' protection level}}
|
||||
var subInnerQualified: Container.PrivateInner? // expected-error {{'PrivateInner' is inaccessible due to 'private' protection level}}
|
||||
}
|
||||
|
||||
|
||||
protocol VeryImportantProto {
|
||||
associatedtype Assoc
|
||||
var value: Int { get set } // expected-note {{protocol requires property 'value' with type 'Int'; do you want to add a stub?}}
|
||||
}
|
||||
|
||||
private struct VIPPrivateType : VeryImportantProto {
|
||||
private typealias Assoc = Int // expected-error {{type alias 'Assoc' must be as accessible as its enclosing type because it matches a requirement in protocol 'VeryImportantProto'}} {{none}}
|
||||
// expected-note@-1 {{mark the type alias as 'fileprivate' to satisfy the requirement}} {{3-10=fileprivate}}
|
||||
var value: Int
|
||||
}
|
||||
|
||||
private struct VIPPrivateProp : VeryImportantProto {
|
||||
typealias Assoc = Int
|
||||
private var value: Int // expected-error {{property 'value' must be as accessible as its enclosing type because it matches a requirement in protocol 'VeryImportantProto'}} {{none}}
|
||||
// expected-note@-1 {{mark the var as 'fileprivate' to satisfy the requirement}} {{3-10=fileprivate}}
|
||||
}
|
||||
|
||||
private struct VIPPrivateSetProp : VeryImportantProto {
|
||||
typealias Assoc = Int
|
||||
private(set) var value: Int // expected-error {{setter for property 'value' must be as accessible as its enclosing type because it matches a requirement in protocol 'VeryImportantProto'}} {{none}}
|
||||
// expected-note@-1 {{mark the var as 'fileprivate' to satisfy the requirement}} {{3-10=fileprivate}}
|
||||
}
|
||||
|
||||
private class VIPPrivateSetBase {
|
||||
private var value: Int = 0
|
||||
}
|
||||
private class VIPPrivateSetSub : VIPPrivateSetBase, VeryImportantProto { // expected-error {{type 'VIPPrivateSetSub' does not conform to protocol 'VeryImportantProto'}}
|
||||
typealias Assoc = Int
|
||||
}
|
||||
|
||||
private class VIPPrivateSetPropBase {
|
||||
private(set) var value: Int = 0
|
||||
// expected-note@-1 {{mark the var as 'fileprivate' to satisfy the requirement}} {{3-10=fileprivate}}
|
||||
}
|
||||
private class VIPPrivateSetPropSub : VIPPrivateSetPropBase, VeryImportantProto {
|
||||
// expected-error@-1 {{setter for property 'value' must be as accessible as its enclosing type because it matches a requirement in protocol 'VeryImportantProto'}} {{none}}
|
||||
typealias Assoc = Int
|
||||
}
|
||||
|
||||
extension Container {
|
||||
private typealias ExtensionConflictingType = Int // expected-note * {{declared here}}
|
||||
}
|
||||
extension Container {
|
||||
private typealias ExtensionConflictingType = Double // expected-note * {{declared here}}
|
||||
}
|
||||
extension Container {
|
||||
func test() {
|
||||
let a: ExtensionConflictingType? = nil // expected-error {{'ExtensionConflictingType' is inaccessible due to 'private' protection level}}
|
||||
let b: Container.ExtensionConflictingType? = nil // expected-error {{'ExtensionConflictingType' is inaccessible due to 'private' protection level}}
|
||||
_ = ExtensionConflictingType() // expected-error {{'ExtensionConflictingType' is inaccessible due to 'private' protection level}}
|
||||
_ = Container.ExtensionConflictingType() // expected-error {{'ExtensionConflictingType' is inaccessible due to 'private' protection level}}
|
||||
}
|
||||
}
|
||||
|
||||
// All of these should be errors, but didn't have the correct behavior in Swift
|
||||
// 3.0GM.
|
||||
extension Container {
|
||||
private struct VeryPrivateStruct { // expected-note * {{type declared here}}
|
||||
private typealias VeryPrivateType = Int // expected-note * {{type declared here}}
|
||||
private struct VeryPrivateInnerStruct {}
|
||||
var privateVar: VeryPrivateType { fatalError() } // expected-warning {{property should be declared private because its type uses a private type}}
|
||||
var privateVar2 = VeryPrivateType() // expected-warning {{property should be declared private because its type 'Container.VeryPrivateStruct.VeryPrivateType' (aka 'Int') uses a private type}}
|
||||
var privateVar3 = VeryPrivateInnerStruct() // expected-warning {{property should be declared private because its type 'Container.VeryPrivateStruct.VeryPrivateInnerStruct' uses a private type}}
|
||||
typealias PrivateAlias = VeryPrivateType // expected-warning {{type alias should be declared private because its underlying type uses a private type}}
|
||||
subscript(_: VeryPrivateType) -> Void { return () } // expected-warning {{subscript should be declared private because its index uses a private type}}
|
||||
func privateMethod(_: VeryPrivateType) -> Void {} // expected-warning {{method should be declared private because its parameter uses a private type}} {{none}}
|
||||
enum PrivateRawValue: VeryPrivateType { // expected-warning {{enum should be declared private because its raw type uses a private type}} {{none}}
|
||||
case A
|
||||
}
|
||||
enum PrivatePayload {
|
||||
case A(VeryPrivateType) // expected-warning {{enum case in an internal enum uses a private type}} {{none}}
|
||||
}
|
||||
|
||||
private class PrivateInnerClass {} // expected-note * {{declared here}}
|
||||
class PrivateSuper: PrivateInnerClass {} // expected-warning {{class should be declared private because its superclass is private}} {{none}}
|
||||
}
|
||||
|
||||
fileprivate var privateVar: VeryPrivateStruct { fatalError() } // expected-warning {{property should not be declared fileprivate because its type uses a private type}} {{none}}
|
||||
fileprivate typealias PrivateAlias = VeryPrivateStruct // expected-warning {{type alias should not be declared fileprivate because its underlying type uses a private type}} {{none}}
|
||||
fileprivate subscript(_: VeryPrivateStruct) -> Void { return () } // expected-warning {{subscript should not be declared fileprivate because its index uses a private type}} {{none}}
|
||||
fileprivate func privateMethod(_: VeryPrivateStruct) -> Void {} // expected-warning {{method should not be declared fileprivate because its parameter uses a private type}} {{none}}
|
||||
fileprivate enum PrivateRawValue: VeryPrivateStruct {} // expected-warning {{enum should not be declared fileprivate because its raw type uses a private type}} {{none}}
|
||||
// expected-error@-1 {{raw type 'Container.VeryPrivateStruct' is not expressible by any literal}}
|
||||
// expected-error@-2 {{'Container.PrivateRawValue' declares raw type 'Container.VeryPrivateStruct', but does not conform to RawRepresentable and conformance could not be synthesized}}
|
||||
// expected-error@-3 {{RawRepresentable conformance cannot be synthesized because raw type 'Container.VeryPrivateStruct' is not Equatable}}
|
||||
fileprivate enum PrivatePayload {
|
||||
case A(VeryPrivateStruct) // expected-warning {{enum case in an internal enum uses a private type}} {{none}}
|
||||
}
|
||||
|
||||
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<T> where T: PrivateInnerClass {} // expected-warning {{generic class should not be declared fileprivate because its generic requirement uses a private type}} {{none}}
|
||||
}
|
||||
|
||||
fileprivate struct SR2579 {
|
||||
private struct Inner {
|
||||
private struct InnerPrivateType {}
|
||||
var innerProperty = InnerPrivateType() // expected-warning {{property should be declared private because its type 'SR2579.Inner.InnerPrivateType' uses a private type}}
|
||||
}
|
||||
// FIXME: We need better errors when one access violation results in more
|
||||
// downstream.
|
||||
private var outerProperty = Inner().innerProperty // expected-warning {{property should not be declared in this context because its type 'SR2579.Inner.InnerPrivateType' uses a private type}}
|
||||
var outerProperty2 = Inner().innerProperty // expected-warning {{property should be declared private because its type 'SR2579.Inner.InnerPrivateType' uses a private type}}
|
||||
}
|
||||
@@ -1,91 +0,0 @@
|
||||
// RUN: %target-typecheck-verify-swift -swift-version 3 -module-name main
|
||||
|
||||
public protocol P {
|
||||
associatedtype Element
|
||||
|
||||
func f() -> Element
|
||||
}
|
||||
|
||||
struct S<T> : P {
|
||||
func f() -> T { while true {} }
|
||||
}
|
||||
|
||||
public struct G<T> {
|
||||
typealias A = S<T> // expected-note {{declared here}}
|
||||
|
||||
public func foo<U : P>(u: U) where U.Element == A.Element {} // expected-warning {{instance method should not be declared public because its generic requirement uses an internal type}}
|
||||
}
|
||||
|
||||
public final class ReplayableGenerator<S: Sequence> : IteratorProtocol {
|
||||
typealias Sequence = S // expected-note {{declared here}}
|
||||
public typealias Element = Sequence.Iterator.Element // expected-warning {{type alias should not be declared public because its underlying type uses an internal type}}
|
||||
|
||||
public func next() -> Element? {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
struct Generic<T> {
|
||||
fileprivate typealias Dependent = T
|
||||
}
|
||||
|
||||
var x: Generic<Int>.Dependent = 3 // expected-warning {{variable should be declared fileprivate because its type uses a fileprivate type}}
|
||||
|
||||
func internalFuncWithFileprivateAlias() -> Generic<Int>.Dependent { // expected-warning {{function should be declared fileprivate because its result uses a fileprivate type}}
|
||||
return 3
|
||||
}
|
||||
|
||||
private func privateFuncWithFileprivateAlias() -> Generic<Int>.Dependent {
|
||||
return 3
|
||||
}
|
||||
|
||||
var y = privateFuncWithFileprivateAlias() // expected-warning{{variable should be declared fileprivate because its type 'Generic<Int>.Dependent' (aka 'Int') uses a fileprivate type}}
|
||||
|
||||
|
||||
private typealias FnType = (_ x: Int) -> Void // expected-note * {{type declared here}}
|
||||
|
||||
public var fn1: (FnType) -> Void = { _ in } // expected-warning {{should not be declared public}}
|
||||
public var fn2: (_ x: FnType) -> Void = { _ in } // expected-warning {{should not be declared public}}
|
||||
public var fn3: (main.FnType) -> Void = { _ in } // expected-warning {{should not be declared public}}
|
||||
public var fn4: (_ x: main.FnType) -> Void = { _ in } // expected-warning {{should not be declared public}}
|
||||
public var nested1: (_ x: (FnType) -> Void) -> Void = { _ in } // expected-warning {{should not be declared public}}
|
||||
public var nested2: (_ x: (main.FnType) -> Void) -> Void = { _ in } // expected-warning {{should not be declared public}}
|
||||
public func test1(x: FnType) {} // expected-warning {{should not be declared public}}
|
||||
public func test2(x: main.FnType) {} // expected-warning {{should not be declared public}}
|
||||
|
||||
|
||||
public func reject1(x: FnType?) {} // expected-error {{cannot be declared public}}
|
||||
public func reject2(x: main.FnType?) {} // expected-error {{cannot be declared public}}
|
||||
public func reject3() -> FnType { fatalError() } // expected-error {{cannot be declared public}}
|
||||
public func reject4() -> main.FnType { fatalError() } // expected-error {{cannot be declared public}}
|
||||
public var rejectVar1: FnType = {_ in } // expected-error {{cannot be declared public}}
|
||||
public var rejectVar2: main.FnType = {_ in } // expected-error {{cannot be declared public}}
|
||||
public var rejectVar3: FnType? // expected-error {{cannot be declared public}}
|
||||
public var rejectVar4: main.FnType? // expected-error {{cannot be declared public}}
|
||||
public var escaping1: (@escaping FnType) -> Void = { _ in } // expected-error {{cannot be declared public}}
|
||||
public var escaping2: (_ x: @escaping FnType) -> Void = { _ in } // expected-error {{cannot be declared public}}
|
||||
public var escaping3: (@escaping main.FnType) -> Void = { _ in } // expected-error {{cannot be declared public}}
|
||||
public var escaping4: (_ x: @escaping main.FnType) -> Void = { _ in } // expected-error {{cannot be declared public}}
|
||||
|
||||
public struct SubscriptTest {
|
||||
public subscript(test1 x: FnType) -> () { return } // expected-warning {{should not be declared public}}
|
||||
public subscript(test2 x: main.FnType) -> () { return } // expected-warning {{should not be declared public}}
|
||||
|
||||
public subscript(reject1 x: FnType?) -> () { return } // expected-error {{cannot be declared public}}
|
||||
public subscript(reject2 x: main.FnType?) -> () { return } // expected-error {{cannot be declared public}}
|
||||
public subscript(reject3 x: Int) -> FnType { fatalError() } // expected-error {{cannot be declared public}}
|
||||
public subscript(reject4 x: Int) -> main.FnType { fatalError() } // expected-error {{cannot be declared public}}
|
||||
}
|
||||
|
||||
private struct ActuallyPrivate {} // expected-note * {{declared here}}
|
||||
private typealias ActuallyPrivateAlias = ActuallyPrivate
|
||||
|
||||
public var failFn: (ActuallyPrivate) -> Void = { _ in } // expected-error {{cannot be declared public}}
|
||||
public var failFn2: (_ x: ActuallyPrivate) -> Void = { _ in } // expected-error {{cannot be declared public}}
|
||||
public var failFn3: (main.ActuallyPrivate) -> Void = { _ in } // expected-error {{cannot be declared public}}
|
||||
public var failFn4: (_ x: main.ActuallyPrivate) -> Void = { _ in } // expected-error {{cannot be declared public}}
|
||||
public var failNested1: (_ x: (ActuallyPrivate) -> Void) -> Void = { _ in } // expected-error {{cannot be declared public}}
|
||||
public var failNested2: (_ x: (main.ActuallyPrivate) -> Void) -> Void = { _ in } // expected-error {{cannot be declared public}}
|
||||
public func failTest(x: ActuallyPrivate) {} // expected-error {{cannot be declared public}}
|
||||
public func failTest2(x: main.ActuallyPrivate) {} // expected-error {{cannot be declared public}}
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
// RUN: %target-typecheck-verify-swift -swift-version 3
|
||||
|
||||
protocol P { }
|
||||
protocol Q { }
|
||||
|
||||
class Foo: AnyObject { } // expected-warning{{conformance of class 'Foo' to 'AnyObject' is redundant}}{{10-21=}}
|
||||
|
||||
class Bar: AnyObject, P { } // expected-warning{{conformance of class 'Bar' to 'AnyObject' is redundant}}{{12-23=}}
|
||||
|
||||
class Wibble: Bar, AnyObject, Q { } // expected-warning{{conformance of class 'Wibble' to 'AnyObject' is redundant}}{{18-29=}}
|
||||
@@ -1,4 +1,3 @@
|
||||
// RUN: %target-typecheck-verify-swift -swift-version 3
|
||||
// RUN: %target-typecheck-verify-swift -swift-version 4
|
||||
// RUN: not %target-swift-frontend -tyepcheck -swift-version 5
|
||||
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
// RUN: %target-typecheck-verify-swift -swift-version 3
|
||||
// Generate a swift 3 compatible warning if final is specified in an extension
|
||||
|
||||
protocol P {}
|
||||
|
||||
extension P {
|
||||
final func inExtension() {} // expected-warning{{functions in a protocol extension do not need to be marked with 'final'}} {{3-9=}}
|
||||
}
|
||||
@@ -1,4 +1,3 @@
|
||||
// RUN: %target-typecheck-verify-swift -swift-version 3
|
||||
// RUN: %target-typecheck-verify-swift -swift-version 4
|
||||
|
||||
// In -swift-version 4 mode, the old spelling is silently parsed as the new spelling.
|
||||
|
||||
@@ -1,28 +0,0 @@
|
||||
// RUN: %target-swift-frontend -enable-objc-interop -disable-objc-attr-requires-foundation-module -typecheck -verify %s -swift-version 3
|
||||
|
||||
class Load1 {
|
||||
class func load() { }
|
||||
class func alloc() {}
|
||||
class func allocWithZone(_: Int) {}
|
||||
class func initialize() {}
|
||||
}
|
||||
|
||||
@objc class Load2 {
|
||||
class func load() { } // expected-error{{method 'load()' defines Objective-C class method 'load', which is not permitted by Swift}}
|
||||
class func alloc() {} // expected-error{{method 'alloc()' defines Objective-C class method 'alloc', which is not permitted by Swift}}
|
||||
class func allocWithZone(_: Int) {} // expected-error{{method 'allocWithZone' defines Objective-C class method 'allocWithZone:', which is not permitted by Swift}}
|
||||
class func initialize() {} // expected-warning{{method 'initialize()' defines Objective-C class method 'initialize', which is not guaranteed to be invoked by Swift and will be disallowed in future versions}}
|
||||
}
|
||||
|
||||
@objc class Load3 {
|
||||
class var load: Load3 {
|
||||
get { return Load3() } // expected-error{{getter for 'load' defines Objective-C class method 'load', which is not permitted by Swift}}
|
||||
set { }
|
||||
}
|
||||
|
||||
@objc(alloc) class var prop: Int { return 0 } // expected-error{{getter for 'prop' defines Objective-C class method 'alloc', which is not permitted by Swift}}
|
||||
@objc(allocWithZone:) class func fooWithZone(_: Int) {} // expected-error{{method 'fooWithZone' defines Objective-C class method 'allocWithZone:', which is not permitted by Swift}}
|
||||
@objc(initialize) class func barnitialize() {} // expected-warning{{method 'barnitialize()' defines Objective-C class method 'initialize', which is not guaranteed to be invoked by Swift and will be disallowed in future versions}}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,18 +0,0 @@
|
||||
// RUN: %target-typecheck-verify-swift -swift-version 3
|
||||
|
||||
public struct Pair<A, B> {}
|
||||
|
||||
public struct PublicStruct {
|
||||
public struct Inner {}
|
||||
@available(*, unavailable)
|
||||
internal struct Obsolete {} // expected-note * {{marked unavailable here}}
|
||||
}
|
||||
|
||||
@available(*, unavailable, renamed: "PublicStruct")
|
||||
public typealias ObsoleteAlias = PublicStruct // expected-note {{marked unavailable here}}
|
||||
|
||||
public let a: ObsoleteAlias.Inner?
|
||||
public let b: ObsoleteAlias.Obsolete? // expected-error {{'Obsolete' is unavailable}}
|
||||
public let c: Pair<ObsoleteAlias.Inner, PublicStruct.Obsolete>? // expected-error {{'Obsolete' is unavailable}}
|
||||
public let c2: Pair<PublicStruct.Obsolete, ObsoleteAlias.Inner>? // expected-error {{'Obsolete' is unavailable}}
|
||||
public let d: ObsoleteAlias? // expected-error {{'ObsoleteAlias' has been renamed to 'PublicStruct'}}
|
||||
@@ -1,128 +0,0 @@
|
||||
// RUN: %empty-directory(%t)
|
||||
// RUN: %gyb %s -o %t/bridging-nsnumber-and-nsvalue.swift
|
||||
// RUN: %target-swift-frontend -typecheck -verify %t/bridging-nsnumber-and-nsvalue.swift -swift-version 3
|
||||
|
||||
// REQUIRES: objc_interop
|
||||
|
||||
// Swift 3.0 accepted "nsNumber as Int" or "nsValue as NSRect" as if they were
|
||||
// safe coercions, when in fact they may fail if the object doesn't represent
|
||||
// the right Swift type.
|
||||
|
||||
import Foundation
|
||||
import CoreGraphics
|
||||
|
||||
%{
|
||||
coercionTypes = {
|
||||
'NSNumber': [
|
||||
'Int',
|
||||
'UInt',
|
||||
'Int64',
|
||||
'UInt64',
|
||||
'Int32',
|
||||
'UInt32',
|
||||
'Int16',
|
||||
'UInt16',
|
||||
'Int8',
|
||||
'UInt8',
|
||||
'Float',
|
||||
'Double',
|
||||
'CGFloat',
|
||||
],
|
||||
'NSValue': [
|
||||
'CGRect',
|
||||
'CGPoint',
|
||||
'CGSize',
|
||||
'NSRange',
|
||||
],
|
||||
}
|
||||
}%
|
||||
|
||||
// For testing purposes, make everything Hashable. Don't do this at home
|
||||
extension Equatable {
|
||||
public static func ==(x: Self, y: Self) -> Bool {
|
||||
fatalError("hella cray")
|
||||
}
|
||||
}
|
||||
extension Hashable { public var hashValue: Int { fatalError("trill hiphy") } }
|
||||
extension CGSize: Hashable {}
|
||||
extension CGPoint: Hashable {}
|
||||
extension CGRect: Hashable {}
|
||||
|
||||
% for ObjectType, ValueTypes in coercionTypes.items():
|
||||
func bridgeNSNumberBackToSpecificType(object: ${ObjectType},
|
||||
optional: ${ObjectType}?,
|
||||
array: [${ObjectType}],
|
||||
dictKeys: [${ObjectType}: Any],
|
||||
dictValues: [AnyHashable: ${ObjectType}],
|
||||
dictBoth: [${ObjectType}: ${ObjectType}],
|
||||
set: Set<${ObjectType}>) {
|
||||
% for Type in ValueTypes:
|
||||
_ = object as ${Type} // expected-warning{{use 'as!'}}
|
||||
_ = object is ${Type}
|
||||
_ = object as? ${Type}
|
||||
_ = object as! ${Type}
|
||||
|
||||
_ = optional as ${Type}? // expected-warning{{use 'as!'}}
|
||||
_ = optional is ${Type}?
|
||||
_ = optional as? ${Type}?
|
||||
_ = optional as! ${Type}?
|
||||
|
||||
// NB: This remains an error, since optional-to-nonoptional requires a
|
||||
// nil check
|
||||
_ = optional as ${Type} // expected-error{{use 'as!'}}
|
||||
_ = optional is ${Type}
|
||||
_ = optional as? ${Type}
|
||||
_ = optional as! ${Type}
|
||||
|
||||
_ = array as [${Type}] // expected-warning{{use 'as!'}}
|
||||
_ = array is [${Type}]
|
||||
_ = array as? [${Type}]
|
||||
_ = array as! [${Type}]
|
||||
|
||||
_ = dictKeys as [${Type}: Any] // expected-warning{{use 'as!'}}
|
||||
_ = dictKeys is [${Type}: Any]
|
||||
_ = dictKeys as? [${Type}: Any]
|
||||
_ = dictKeys as! [${Type}: Any]
|
||||
|
||||
_ = dictKeys as [${Type}: AnyObject] // expected-warning{{use 'as!'}}
|
||||
_ = dictKeys is [${Type}: AnyObject]
|
||||
_ = dictKeys as? [${Type}: AnyObject]
|
||||
_ = dictKeys as! [${Type}: AnyObject]
|
||||
|
||||
_ = dictValues as [AnyHashable: ${Type}] // expected-warning{{use 'as!'}}
|
||||
_ = dictValues is [AnyHashable: ${Type}]
|
||||
_ = dictValues as? [AnyHashable: ${Type}]
|
||||
_ = dictValues as! [AnyHashable: ${Type}]
|
||||
|
||||
_ = dictValues as [NSObject: ${Type}] // expected-warning{{use 'as!'}}
|
||||
_ = dictValues is [NSObject: ${Type}]
|
||||
_ = dictValues as? [NSObject: ${Type}]
|
||||
_ = dictValues as! [NSObject: ${Type}]
|
||||
|
||||
_ = dictBoth as [${ObjectType}: ${Type}] // expected-warning{{use 'as!'}}
|
||||
_ = dictBoth is [${ObjectType}: ${Type}]
|
||||
_ = dictBoth as? [${ObjectType}: ${Type}]
|
||||
_ = dictBoth as! [${ObjectType}: ${Type}]
|
||||
|
||||
_ = dictBoth as [${Type}: ${ObjectType}] // expected-warning{{use 'as!'}}
|
||||
_ = dictBoth is [${Type}: ${ObjectType}]
|
||||
_ = dictBoth as? [${Type}: ${ObjectType}]
|
||||
_ = dictBoth as! [${Type}: ${ObjectType}]
|
||||
|
||||
_ = dictBoth as [${Type}: ${Type}] // expected-warning{{use 'as!'}}
|
||||
_ = dictBoth is [${Type}: ${Type}]
|
||||
_ = dictBoth as? [${Type}: ${Type}]
|
||||
_ = dictBoth as! [${Type}: ${Type}]
|
||||
|
||||
_ = set as Set<${Type}> // expected-warning{{use 'as!'}}
|
||||
_ = set is Set<${Type}>
|
||||
_ = set as? Set<${Type}>
|
||||
_ = set as! Set<${Type}>
|
||||
% end
|
||||
|
||||
_ = object is String // expected-warning{{always fails}}
|
||||
_ = [object] is String // expected-warning{{always fails}}
|
||||
_ = object as? String // expected-warning{{always fails}}
|
||||
_ = object as! String // expected-warning{{always fails}}
|
||||
}
|
||||
% end
|
||||
@@ -1,168 +0,0 @@
|
||||
// RUN: %target-typecheck-verify-swift -D FOO -swift-version 3
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Invalid binary operation
|
||||
|
||||
#if FOO = false
|
||||
// expected-warning @-1 {{ignoring invalid conditional compilation expression, which will be rejected in future version of Swift}}
|
||||
undefinedFunc() // expected-error {{use of unresolved identifier 'undefinedFunc'}}
|
||||
#else
|
||||
undefinedFunc() // ignored.
|
||||
#endif
|
||||
|
||||
#if false
|
||||
|
||||
#elseif !FOO ? false : true
|
||||
// expected-warning @-1 {{ignoring invalid conditional compilation expression, which will be rejected in future version of Swift}}
|
||||
undefinedFunc() // ignored.
|
||||
#else
|
||||
undefinedFunc() // expected-error {{use of unresolved identifier 'undefinedFunc'}}
|
||||
#endif
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// SR-3663: The precedence and associativity of '||' and '&&'.
|
||||
// See test/Parse/ConditionalCompilation/sequence.swift for Swift 4 behavior.
|
||||
|
||||
// expected-warning @+1 {{future version of Swift have different rule for evaluating condition; add parentheses to make the condition compatible with Swift4}} {{14-14=(}} {{27-27=)}}
|
||||
#if false || true && false
|
||||
undefinedIf() // expected-error {{use of unresolved identifier 'undefinedIf'}}
|
||||
#else
|
||||
undefinedElse()
|
||||
#endif
|
||||
|
||||
// expected-warning @+1 {{future version of Swift have different rule for evaluating condition; add parentheses to make the condition compatible with Swift4}} {{5-5=(}} {{18-18=)}}
|
||||
#if false && true || true
|
||||
undefinedIf()
|
||||
#else
|
||||
undefinedElse() // expected-error {{use of unresolved identifier 'undefinedElse'}}
|
||||
#endif
|
||||
|
||||
// expected-warning @+1 {{future version of Swift have different rule for evaluating condition; add parentheses to make the condition compatible with Swift4}} {{14-14=(}} {{27-27=)}}
|
||||
#if false || true && false || false
|
||||
undefinedIf() // expected-error {{use of unresolved identifier 'undefinedIf'}}
|
||||
#else
|
||||
undefinedElse()
|
||||
#endif
|
||||
|
||||
// expected-warning @+1 {{future version of Swift have different rule for evaluating condition; add parentheses to make the condition compatible with Swift4}} {{5-5=(}} {{18-18=)}} {{22-22=(}} {{42-42=)}}
|
||||
#if true && false || true && true && true
|
||||
undefinedIf()
|
||||
#else
|
||||
undefinedElse() // expected-error {{use of unresolved identifier 'undefinedElse'}}
|
||||
#endif
|
||||
|
||||
// Accepted in Swift3. *source breaking*
|
||||
#if false || true && try! Swift
|
||||
// expected-error @-1 {{invalid conditional compilation expression}}
|
||||
// expected-warning @-2 {{future version of Swift have different rule for evaluating condition; add parentheses to make the condition compatible with Swift4}} {{14-14=(}} {{32-32=)}}
|
||||
undefinedIf()
|
||||
#endif
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// SR-4032: "skip parsing" in non-active branch for version checks.
|
||||
// See test/Parse/ConditionalCompilation/sequence_version.swift for Swift 4 behavior.
|
||||
|
||||
#if !swift(>=2.2)
|
||||
// There should be no error here.
|
||||
foo bar
|
||||
#else
|
||||
let _: Int = 1
|
||||
#endif
|
||||
|
||||
#if !compiler(>=4.1)
|
||||
// There should be no error here.
|
||||
foo bar
|
||||
#else
|
||||
let _: Int = 1
|
||||
#endif
|
||||
|
||||
#if (swift(>=2.2))
|
||||
let _: Int = 1
|
||||
#else
|
||||
// There should be no error here.
|
||||
foo bar
|
||||
#endif
|
||||
|
||||
#if (compiler(>=4.1))
|
||||
let _: Int = 1
|
||||
#else
|
||||
// There should be no error here.
|
||||
foo bar
|
||||
#endif
|
||||
|
||||
#if swift(>=99.0) || swift(>=88.1.1)
|
||||
// There should be no error here.
|
||||
foo bar baz // expected-error 2 {{consecutive statements}}
|
||||
#else
|
||||
undefinedElse() // expected-error {{use of unresolved identifier 'undefinedElse'}}
|
||||
#endif
|
||||
|
||||
#if compiler(>=99.0) || compiler(>=88.1.1)
|
||||
// There should be no error here.
|
||||
foo bar baz // expected-error 2 {{consecutive statements}}
|
||||
#else
|
||||
undefinedElse() // expected-error {{use of unresolved identifier 'undefinedElse'}}
|
||||
#endif
|
||||
|
||||
#if swift(>=99.0) || FOO
|
||||
undefinedIf() // expected-error {{use of unresolved identifier 'undefinedIf'}}
|
||||
#else
|
||||
undefinedElse()
|
||||
#endif
|
||||
|
||||
#if compiler(>=99.0) || FOO
|
||||
undefinedIf() // expected-error {{use of unresolved identifier 'undefinedIf'}}
|
||||
#else
|
||||
undefinedElse()
|
||||
#endif
|
||||
|
||||
#if swift(>=99.0) && FOO
|
||||
// There should be no error here.
|
||||
foo bar baz // expected-error 2 {{consecutive statements}}
|
||||
#else
|
||||
undefinedElse() // expected-error {{use of unresolved identifier 'undefinedElse'}}
|
||||
#endif
|
||||
|
||||
#if compiler(>=99.0) && FOO
|
||||
// There should be no error here.
|
||||
foo bar baz // expected-error 2 {{consecutive statements}}
|
||||
#else
|
||||
undefinedElse() // expected-error {{use of unresolved identifier 'undefinedElse'}}
|
||||
#endif
|
||||
|
||||
#if FOO && swift(>=2.2)
|
||||
undefinedIf() // expected-error {{use of unresolved identifier 'undefinedIf'}}
|
||||
#else
|
||||
// There should be no error here.
|
||||
foo bar baz // expected-error 2 {{consecutive statements}}
|
||||
#endif
|
||||
|
||||
#if FOO && compiler(>=4.0)
|
||||
undefinedIf() // expected-error {{use of unresolved identifier 'undefinedIf'}}
|
||||
#else
|
||||
// There should be no error here.
|
||||
foo bar baz // expected-error 2 {{consecutive statements}}
|
||||
#endif
|
||||
|
||||
#if swift(>=2.2) && swift(>=1)
|
||||
undefinedIf() // expected-error {{use of unresolved identifier 'undefinedIf'}}
|
||||
#else
|
||||
// There should be no error here.
|
||||
foo bar baz // expected-error 2 {{consecutive statements}}
|
||||
#endif
|
||||
|
||||
#if compiler(>=4.1) && compiler(>=4)
|
||||
undefinedIf() // expected-error {{use of unresolved identifier 'undefinedIf'}}
|
||||
#else
|
||||
// There should be no error here.
|
||||
foo bar baz // expected-error 2 {{consecutive statements}}
|
||||
#endif
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// SR-4031: Compound name in compilation condition
|
||||
// See test/Parse/ConditionalCompilation/compoundName_swift4.swift for Swfit 4 behavior
|
||||
|
||||
#if BAR(_:) // expected-warning {{ignoring parentheses in compound name, which will be rejected in future version of Swift}} {{8-12=}}
|
||||
#elseif os(x:)(macOS) // expected-warning {{ignoring parentheses in compound name, which will be rejected in future version of Swift}} {{11-15=}}
|
||||
#elseif os(Linux(foo:bar:)) // expected-warning {{ignoring parentheses in compound name, which will be rejected in future version of Swift}} {{17-27=}}
|
||||
#endif
|
||||
@@ -1,13 +0,0 @@
|
||||
// RUN: %target-typecheck-verify-swift -swift-version 3
|
||||
|
||||
// Swift 3 used default literal types even for normal protocol constraints,
|
||||
// which led to nonsensical type inference behavior.
|
||||
|
||||
func f<T: ExpressibleByIntegerLiteral>(_: T = 0) { }
|
||||
f()
|
||||
|
||||
struct X<T: ExpressibleByIntegerLiteral> {
|
||||
func g() { }
|
||||
}
|
||||
|
||||
X().g()
|
||||
@@ -1,82 +0,0 @@
|
||||
// RUN: %target-swift-frontend -typecheck -verify %s -swift-version 3
|
||||
|
||||
protocol Mashable { }
|
||||
protocol Womparable { }
|
||||
|
||||
// FuncDecl: Choose 0
|
||||
func f1<T>(x: T) {}
|
||||
|
||||
// FuncDecl: Choose 1
|
||||
// 1: Inherited constraint
|
||||
func f2<T: Mashable>(x: T) {} // no-warning
|
||||
// 2: Non-trailing where
|
||||
func f3<T where T: Womparable>(x: T) {} // expected-warning {{'where' clause next to generic parameters is deprecated and will be removed in the future version of Swift}} {{10-30=}} {{37-37= where T: Womparable}}
|
||||
// 3: Has return type
|
||||
func f4<T>(x: T) -> Int { return 2 } // no-warning
|
||||
// 4: Trailing where
|
||||
func f5<T>(x: T) where T : Equatable {} // no-warning
|
||||
|
||||
// FuncDecl: Choose 2
|
||||
// 1,2
|
||||
func f12<T: Mashable where T: Womparable>(x: T) {} // expected-warning {{'where' clause next to generic parameters is deprecated and will be removed in the future version of Swift}} {{21-41=}} {{48-48= where T: Womparable}}
|
||||
// 1,3
|
||||
func f13<T: Mashable>(x: T) -> Int { return 2 } // no-warning
|
||||
// 1,4
|
||||
func f14<T: Mashable>(x: T) where T: Equatable {} // no-warning
|
||||
// 2,3
|
||||
func f23<T where T: Womparable>(x: T) -> Int { return 2 } // expected-warning {{'where' clause next to generic parameters is deprecated and will be removed in the future version of Swift}} {{11-31=}} {{45-45= where T: Womparable}}
|
||||
// 2,4
|
||||
func f24<T where T: Womparable>(x: T) where T: Equatable {} // expected-warning {{'where' clause next to generic parameters is deprecated and will be removed in the future version of Swift}} {{11-31=}} {{39-44=where T: Womparable,}}
|
||||
// 3,4
|
||||
func f34<T>(x: T) -> Int where T: Equatable { return 2 } // no-warning
|
||||
|
||||
// FuncDecl: Choose 3
|
||||
// 1,2,3
|
||||
func f123<T: Mashable where T: Womparable>(x: T) -> Int { return 2 } // expected-warning {{'where' clause next to generic parameters is deprecated and will be removed in the future version of Swift}} {{22-42=}} {{56-56= where T: Womparable}}
|
||||
// 1,2,4
|
||||
func f124<T: Mashable where T: Womparable>(x: T) where T: Equatable {} // expected-warning {{'where' clause next to generic parameters is deprecated and will be removed in the future version of Swift}} {{22-42=}} {{50-55=where T: Womparable,}}
|
||||
// 2,3,4
|
||||
func f234<T where T: Womparable>(x: T) -> Int where T: Equatable { return 2 } // expected-warning {{'where' clause next to generic parameters is deprecated and will be removed in the future version of Swift}} {{12-32=}} {{47-52=where T: Womparable,}}
|
||||
|
||||
// FuncDecl: Choose 4
|
||||
// 1,2,3,4
|
||||
func f1234<T: Mashable where T: Womparable>(x: T) -> Int where T: Equatable { return 2 } // expected-warning {{'where' clause next to generic parameters is deprecated and will be removed in the future version of Swift}} {{23-43=}} {{58-63=where T: Womparable,}}
|
||||
|
||||
|
||||
|
||||
// NominalTypeDecl: Choose 0
|
||||
struct S0<T> {}
|
||||
|
||||
// NominalTypeDecl: Choose 1
|
||||
// 1: Inherited constraint
|
||||
struct S1<T: Mashable> {} // no-warning
|
||||
// 2: Non-trailing where
|
||||
struct S2<T where T: Womparable> {} // expected-warning {{'where' clause next to generic parameters is deprecated and will be removed in the future version of Swift}} {{12-32=}} {{33-33= where T: Womparable}}
|
||||
// 3: Trailing where
|
||||
struct S3<T> where T : Equatable {} // no-warning
|
||||
|
||||
// NominalTypeDecl: Choose 2
|
||||
// 1,2
|
||||
struct S12<T: Mashable where T: Womparable> {} // expected-warning {{'where' clause next to generic parameters is deprecated and will be removed in the future version of Swift}} {{23-43=}} {{44-44= where T: Womparable}}
|
||||
// 1,3
|
||||
struct S13<T: Mashable> where T: Equatable {} // no-warning
|
||||
// 2,3
|
||||
struct S23<T where T: Womparable> where T: Equatable {} // expected-warning {{'where' clause next to generic parameters is deprecated and will be removed in the future version of Swift}} {{13-33=}} {{35-40=where T: Womparable,}}
|
||||
|
||||
// NominalTypeDecl: Choose 3
|
||||
// 1,2,3
|
||||
struct S123<T: Mashable where T: Womparable> where T: Equatable {} // expected-warning {{'where' clause next to generic parameters is deprecated and will be removed in the future version of Swift}} {{24-44=}} {{46-51=where T: Womparable,}}
|
||||
|
||||
|
||||
protocol ProtoA {}
|
||||
protocol ProtoB {}
|
||||
protocol ProtoC {}
|
||||
protocol ProtoD {}
|
||||
func testCombinedConstraints<T: ProtoA & ProtoB where T: ProtoC>(x: T) {} // expected-warning {{'where' clause next to generic parameters is deprecated and will be removed in the future version of Swift}} {{48-64=}} {{71-71= where T: ProtoC}}
|
||||
func testCombinedConstraints<T: ProtoA & ProtoB where T: ProtoC>(x: T) where T: ProtoD {} // expected-warning {{'where' clause next to generic parameters is deprecated and will be removed in the future version of Swift}} {{48-64=}} {{72-77=where T: ProtoC,}}
|
||||
|
||||
func testCombinedConstraintsOld<T: protocol<ProtoA, ProtoB> where T: ProtoC>(x: T) {} // expected-warning {{'where' clause next to generic parameters is deprecated and will be removed in the future version of Swift}} {{60-76=}} {{83-83= where T: ProtoC}}
|
||||
// expected-warning@-1 {{'protocol<...>' composition syntax is deprecated}}
|
||||
func testCombinedConstraintsOld<T: protocol<ProtoA, ProtoB> where T: ProtoC>(x: T) where T: ProtoD {} // expected-warning {{'where' clause next to generic parameters is deprecated and will be removed in the future version of Swift}} {{60-76=}} {{84-89=where T: ProtoC,}}
|
||||
// expected-warning@-1 {{'protocol<...>' composition syntax is deprecated}}
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
// RUN: %target-typecheck-verify-swift -swift-version 3
|
||||
|
||||
// Dollar is allowed as an identifier head in Swift 3.
|
||||
|
||||
func dollarVar() {
|
||||
var $ : Int = 42 // No error
|
||||
$ += 1
|
||||
print($)
|
||||
}
|
||||
func dollarLet() {
|
||||
let $ = 42 // No error
|
||||
print($)
|
||||
}
|
||||
func dollarClass() {
|
||||
class $ {} // No error
|
||||
}
|
||||
func dollarEnum() {
|
||||
enum $ {} // No error
|
||||
}
|
||||
func dollarStruct() {
|
||||
struct $ {} // No error
|
||||
}
|
||||
|
||||
@@ -1,13 +0,0 @@
|
||||
// RUN: %target-typecheck-verify-swift -swift-version 3
|
||||
|
||||
// Static function in protocol should have `Self.` instead of its protocol name
|
||||
protocol P {}
|
||||
|
||||
extension P {
|
||||
static func f1() {}
|
||||
|
||||
func g() {
|
||||
f1() // expected-error {{use of unresolved identifier 'f1'}}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,109 +0,0 @@
|
||||
// RUN: %target-typecheck-verify-swift -swift-version 3
|
||||
|
||||
// Tests for enum case behavior in Swift 3
|
||||
|
||||
enum E {
|
||||
case foo(bar: String)
|
||||
case bar(_: String)
|
||||
case two(x: Int, y: Int)
|
||||
case tuple((x: Int, y: Int))
|
||||
}
|
||||
|
||||
enum G_E<T> {
|
||||
case foo(bar: T)
|
||||
case bar(_: T)
|
||||
case two(x: T, y: T)
|
||||
case tuple((x: T, y: T))
|
||||
}
|
||||
|
||||
let arr: [String] = []
|
||||
let _ = arr.map(E.foo) // Ok
|
||||
let _ = arr.map(E.bar) // Ok
|
||||
let _ = arr.map(E.two) // expected-error {{cannot invoke 'map' with an argument list of type '((Int, Int) -> E)'}}
|
||||
// expected-note@-1{{expected an argument list of type '((Self.Element) throws -> T)'}}
|
||||
let _ = arr.map(E.tuple) // expected-error {{cannot invoke 'map' with an argument list of type '(((x: Int, y: Int)) -> E)'}}
|
||||
// expected-note@-1{{expected an argument list of type '((Self.Element) throws -> T)'}}
|
||||
|
||||
let _ = arr.map(G_E<String>.foo) // Ok
|
||||
let _ = arr.map(G_E<String>.bar) // Ok
|
||||
let _ = arr.map(G_E<String>.two) // expected-error {{cannot invoke 'map' with an argument list of type '((String, String) -> G_E<String>)'}}
|
||||
// expected-note@-1{{expected an argument list of type '((Self.Element) throws -> T)'}}
|
||||
|
||||
let _ = arr.map(G_E<Int>.tuple) // expected-error {{cannot invoke 'map' with an argument list of type '(((x: Int, y: Int)) -> G_E<Int>)'}}
|
||||
// expected-note@-1{{expected an argument list of type '((Self.Element) throws -> T)'}}
|
||||
|
||||
let _ = E.foo("hello") // expected-error {{missing argument label 'bar:' in call}}
|
||||
let _ = E.bar("hello") // Ok
|
||||
|
||||
let _ = G_E<String>.foo("hello") // expected-error {{missing argument label 'bar:' in call}}
|
||||
let _ = G_E<String>.bar("hello") // Ok
|
||||
|
||||
// Passing enum case as an argument to generic function
|
||||
|
||||
func bar_1<T>(_: (T) -> E) {}
|
||||
func bar_2<T>(_: (T) -> G_E<T>) {}
|
||||
func bar_3<T, U>(_: (T) -> G_E<U>) {}
|
||||
|
||||
bar_1(E.foo) // Ok
|
||||
bar_1(E.bar) // Ok
|
||||
bar_1(E.two) // Ok in Swift 3
|
||||
bar_1(E.tuple) // Ok - it's going to be ((x: Int, y: Int))
|
||||
|
||||
bar_2(G_E<String>.foo) // Ok
|
||||
bar_2(G_E<Int>.bar) // Ok
|
||||
bar_2(G_E<Int>.two) // expected-error {{cannot convert value of type '(Int, Int) -> G_E<Int>' to expected argument type '(_) -> G_E<_>'}}
|
||||
bar_2(G_E<Int>.tuple) // expected-error {{cannot convert value of type '((x: Int, y: Int)) -> G_E<Int>' to expected argument type '(_) -> G_E<_>'}}
|
||||
bar_3(G_E<Int>.tuple) // Ok
|
||||
|
||||
// Regular enum case assigned as a value
|
||||
|
||||
let foo: (String) -> E = E.foo // Ok
|
||||
let _ = foo("hello") // Ok
|
||||
|
||||
let bar: (String) -> E = E.bar // Ok
|
||||
let _ = bar("hello") // Ok
|
||||
|
||||
let two: (Int, Int) -> E = E.two // Ok
|
||||
let _ = two(0, 42) // Ok
|
||||
|
||||
let tuple: ((x: Int, y: Int)) -> E = E.tuple // Ok
|
||||
let _ = tuple((x: 0, y: 42)) // Ok
|
||||
|
||||
// Generic enum case assigned as a value
|
||||
|
||||
let g_foo: (String) -> G_E<String> = G_E<String>.foo // Ok
|
||||
let _ = g_foo("hello") // Ok
|
||||
|
||||
let g_bar: (String) -> G_E<String> = G_E<String>.bar // Ok
|
||||
let _ = g_bar("hello") // Ok
|
||||
|
||||
let g_two: (Int, Int) -> G_E<Int> = G_E<Int>.two // Ok
|
||||
let _ = g_two(0, 42) // Ok
|
||||
|
||||
let g_tuple: ((x: Int, y: Int)) -> G_E<Int> = G_E<Int>.tuple // Ok
|
||||
let _ = g_tuple((x: 0, y: 42)) // Ok
|
||||
|
||||
// Following example doesn't work in Swift 3 mode because Foo.a and Foo.b have different argument types
|
||||
// since the labels are not striped from them.
|
||||
|
||||
enum Foo {
|
||||
case a(x: Int)
|
||||
case b(y: Int)
|
||||
}
|
||||
|
||||
func foo<T>(_: T, _: T) {}
|
||||
foo(Foo.a, Foo.b) // expected-error {{cannot invoke 'foo' with an argument list of type '((Int) -> Foo, (Int) -> Foo)}}
|
||||
// expected-note@-1 {{expected an argument list of type '(T, T)'}}
|
||||
|
||||
// rdar://problem/32551313 - Useless SE-0110 diagnostic (only in Swift 4 mode)
|
||||
|
||||
enum E_32551313<L, R> {
|
||||
case Left(L)
|
||||
case Right(R)
|
||||
}
|
||||
|
||||
struct Foo_32551313 {
|
||||
static func bar() -> E_32551313<(String, Foo_32551313?), (String, String)>? {
|
||||
return E_32551313.Left("", Foo_32551313()) // Ok
|
||||
}
|
||||
}
|
||||
@@ -1,54 +0,0 @@
|
||||
// RUN: %target-typecheck-verify-swift -swift-version 3
|
||||
|
||||
// https://bugs.swift.org/browse/SR-3452
|
||||
// See test/Parse/enum_element_pattern_swift4.swift for Swift4 behavior.
|
||||
|
||||
enum E {
|
||||
case A, B, C, D
|
||||
|
||||
static func testE(e: E) {
|
||||
switch e {
|
||||
case A<UndefinedTy>(): // expected-warning {{cannot specialize enum case; ignoring generic argument, which will be rejected in future version of Swift}} {{11-24=}}
|
||||
break
|
||||
case B<Int>(): // expected-warning {{cannot specialize enum case; ignoring generic argument, which will be rejected in future version of Swift}} {{11-16=}}
|
||||
break
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func testE(e: E) {
|
||||
switch e {
|
||||
case E.A<UndefinedTy>(): // expected-warning {{cannot specialize enum case; ignoring generic argument, which will be rejected in future version of Swift}} {{11-24=}}
|
||||
break
|
||||
case E.B<Int>(): // expected-warning {{cannot specialize enum case; ignoring generic argument, which will be rejected in future version of Swift}} {{11-16=}}
|
||||
break
|
||||
case .C(): // Ok.
|
||||
break
|
||||
case .D(let payload): // Ok. 'payload' has type '()'.
|
||||
let _: () = payload
|
||||
break
|
||||
default:
|
||||
break
|
||||
}
|
||||
|
||||
guard
|
||||
case .C() = e, // Ok. SILGen assert this, but no-assert Swift3 GM build didn't assert.
|
||||
case .D(let payload) = e // FIXME: Should be rejected. Swift3 IRGen verifier did catch this.
|
||||
else { return }
|
||||
print(payload)
|
||||
}
|
||||
|
||||
extension E : Error {}
|
||||
func canThrow() throws {
|
||||
throw E.A
|
||||
}
|
||||
|
||||
do {
|
||||
try canThrow()
|
||||
} catch E.A() { // Ok.
|
||||
// ..
|
||||
} catch E.B(let payload) { // Ok. 'payload' has type '()'.
|
||||
let _: () = payload
|
||||
}
|
||||
@@ -1,4 +1,3 @@
|
||||
// RUN: %target-typecheck-verify-swift -swift-version 3 -enable-resilience
|
||||
// RUN: %target-typecheck-verify-swift -swift-version 4 -enable-resilience
|
||||
|
||||
func foo(a: Int?, b: Int?) -> Int {
|
||||
|
||||
@@ -1,57 +0,0 @@
|
||||
// RUN: %target-typecheck-verify-swift -parse-as-library -swift-version 3
|
||||
|
||||
class ReferenceSelfInLazyProperty {
|
||||
lazy var refs = (i, f())
|
||||
// expected-error@-1 {{cannot use instance member 'i' within property initializer; property initializers run before 'self' is available}}
|
||||
lazy var trefs: (Int, Int) = (i, f())
|
||||
// expected-error@-1 {{cannot use instance member 'i' within property initializer; property initializers run before 'self' is available}}
|
||||
|
||||
lazy var qrefs = (self.i, self.f())
|
||||
lazy var qtrefs: (Int, Int) = (self.i, self.f())
|
||||
|
||||
lazy var crefs = { (i, f()) }()
|
||||
// expected-error@-1 {{instance member 'i' cannot be used on type 'ReferenceSelfInLazyProperty'}}
|
||||
|
||||
lazy var ctrefs: (Int, Int) = { (i, f()) }()
|
||||
// expected-error@-1 {{instance member 'i' cannot be used on type 'ReferenceSelfInLazyProperty'}}
|
||||
|
||||
lazy var cqrefs = { (self.i, self.f()) }()
|
||||
lazy var cqtrefs: (Int, Int) = { (self.i, self.f()) }()
|
||||
|
||||
lazy var mrefs = { () -> (Int, Int) in return (i, f()) }()
|
||||
// expected-error@-1 {{instance member 'i' cannot be used on type 'ReferenceSelfInLazyProperty'}}
|
||||
|
||||
lazy var mtrefs: (Int, Int) = { return (i, f()) }()
|
||||
// expected-error@-1 {{instance member 'i' cannot be used on type 'ReferenceSelfInLazyProperty'}}
|
||||
|
||||
lazy var mqrefs = { () -> (Int, Int) in (self.i, self.f()) }()
|
||||
lazy var mqtrefs: (Int, Int) = { return (self.i, self.f()) }()
|
||||
|
||||
lazy var lcqrefs = { [unowned self] in (self.i, self.f()) }()
|
||||
lazy var lcqtrefs: (Int, Int) = { [unowned self] in (self.i, self.f()) }()
|
||||
|
||||
lazy var lmrefs = { [unowned self] () -> (Int, Int) in return (i, f()) }()
|
||||
// expected-error@-1 {{instance member 'i' cannot be used on type 'ReferenceSelfInLazyProperty'}}
|
||||
lazy var lmtrefs: (Int, Int) = { [unowned self] in return (i, f()) }()
|
||||
// expected-error@-1 {{instance member 'i' cannot be used on type 'ReferenceSelfInLazyProperty'}}
|
||||
|
||||
lazy var lmqrefs = { [unowned self] () -> (Int, Int) in (self.i, self.f()) }()
|
||||
lazy var lmqtrefs: (Int, Int) = { [unowned self] in return (self.i, self.f()) }()
|
||||
|
||||
var i = 42
|
||||
func f() -> Int { return 0 }
|
||||
}
|
||||
|
||||
class ReferenceStaticInLazyProperty {
|
||||
lazy var refs1 = i
|
||||
lazy var refs2 = f()
|
||||
// expected-error@-1 {{use of unresolved identifier 'f'}}
|
||||
|
||||
lazy var trefs1: Int = i
|
||||
lazy var trefs2: Int = f()
|
||||
// expected-error@-1 {{use of unresolved identifier 'f'}}
|
||||
|
||||
static var i = 42
|
||||
static func f() -> Int { return 0 }
|
||||
// expected-note@-1 2 {{did you mean 'f'?}}
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
// RUN: %target-typecheck-verify-swift -swift-version 3
|
||||
|
||||
struct X {
|
||||
func f1(_ i: Int) { }
|
||||
mutating func f1(_ f: Float) { }
|
||||
}
|
||||
|
||||
func g0(_: (inout X) -> (Float) -> ()) {}
|
||||
|
||||
g0(X.f1) // expected-warning{{partial application of 'mutating' method}}
|
||||
@@ -1,11 +0,0 @@
|
||||
// RUN: %target-typecheck-verify-swift -parse-as-library -swift-version 3 -enable-objc-interop
|
||||
|
||||
class A {
|
||||
@objc func objcVirtualFunction() { } // expected-note{{overridden declaration is here}}
|
||||
}
|
||||
|
||||
class B : A { }
|
||||
|
||||
extension B {
|
||||
override func objcVirtualFunction() { } // expected-warning{{cannot override a non-dynamic class declaration from an extension}}
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
// RUN: %empty-directory(%t)
|
||||
// RUN: %{python} %utils/split_file.py -o %t %s
|
||||
// RUN: %target-swift-frontend -typecheck -primary-file %t/swift3.swift %t/common.swift -verify -swift-version 3
|
||||
// RUN: %target-swift-frontend -typecheck -primary-file %t/swift4.swift %t/common.swift -verify -swift-version 4
|
||||
|
||||
// BEGIN common.swift
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
// RUN: %target-typecheck-verify-swift -swift-version 3
|
||||
|
||||
// REQUIRES: objc_interop
|
||||
|
||||
import Foundation
|
||||
|
||||
extension NSRange : Hashable { // expected-warning{{conformance of '_NSRange' to protocol 'Hashable' was already stated in the type's module 'Foundation'}}
|
||||
var hashValue: Int { return 0 } // expected-note{{var 'hashValue' will not be used to satisfy the conformance to 'Hashable'}}
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
// RUN: %target-typecheck-verify-swift -swift-version 3
|
||||
|
||||
// Note: while Swift 3.2 originally intended to provide backward
|
||||
// compatibility here, the type-soundness issue was considered so severe
|
||||
// (due to it breaking the optimizer) that that we escalated it to an
|
||||
// error.
|
||||
|
||||
protocol P {
|
||||
associatedtype T
|
||||
}
|
||||
|
||||
protocol Q {
|
||||
func foo<T: P>(_: T, _: T.T) where T.T == Self
|
||||
}
|
||||
|
||||
class C1: Q {
|
||||
func foo<T: P>(_: T, _: C1) where T.T == C1 {} // expected-error{{instance method 'foo' in non-final class 'C1' cannot be used to satisfy requirement instance method 'foo' (in protocol 'Q') due to same-type requirement involving 'Self'}}}}
|
||||
// expected-note@-1{{consider weakening the same-type requirement 'T.T' == 'C1' to a superclass requirement}}{{41-43=:}}
|
||||
}
|
||||
|
||||
final class C2: Q {
|
||||
func foo<T: P>(_: T, _: C2) where T.T == C2 {}
|
||||
}
|
||||
|
||||
class C3: Q {
|
||||
func foo<T: P>(_: T, _: C3) where T.T: C3 {}
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
// RUN: %target-typecheck-verify-swift -swift-version 3
|
||||
|
||||
// SR-3842
|
||||
func test(years: [Int]) {
|
||||
_ = years.map(String.init)
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
// RUN: %target-typecheck-verify-swift -swift-version 3
|
||||
|
||||
extension String : Collection { // expected-warning{{conformance of 'String' to protocol 'Collection' was already stated in the type's module 'Swift'}}
|
||||
subscript (i: Index) -> String { // expected-note{{subscript 'subscript' will not be used to satisfy the conformance to 'Collection'}}
|
||||
get { return self }
|
||||
set { }
|
||||
}
|
||||
|
||||
var isEmpty: Bool { return false } // expected-note{{var 'isEmpty' will not be used to satisfy the conformance to 'Collection'}}
|
||||
|
||||
}
|
||||
|
||||
func testStringOps(s: String) {
|
||||
_ = s.isEmpty
|
||||
}
|
||||
@@ -1,14 +1,5 @@
|
||||
// RUN: %empty-directory(%t)
|
||||
// RUN: %{python} %utils/split_file.py -o %t %s
|
||||
// RUN: %target-swift-frontend -parse -primary-file %t/swift3.swift -verify -swift-version 3
|
||||
// RUN: %target-swift-frontend -parse -primary-file %t/swift4.swift -verify -swift-version 4
|
||||
// RUN: %target-swift-frontend -parse -primary-file %s -verify -swift-version 4
|
||||
|
||||
// 'throws' or 'rethrows' are allowed as an identifier in Swift 3.
|
||||
|
||||
// BEGIN swift3.swift
|
||||
class C<throws> {}
|
||||
precedencegroup rethrows {}
|
||||
|
||||
// BEGIN swift4.swift
|
||||
class C<throws> {} // expected-error {{expected an identifier to name generic parameter}}
|
||||
precedencegroup rethrows {} // expected-error {{expected identifier after 'precedencegroup'}}
|
||||
|
||||
@@ -1,370 +0,0 @@
|
||||
// RUN: %target-typecheck-verify-swift -swift-version 3
|
||||
// Originally expr/closure/trailing.swift
|
||||
|
||||
@discardableResult
|
||||
func takeFunc(_ f: (Int) -> Int) -> Int {}
|
||||
func takeValueAndFunc(_ value: Int, _ f: (Int) -> Int) {}
|
||||
func takeTwoFuncs(_ f: (Int) -> Int, _ g: (Int) -> Int) {}
|
||||
func takeFuncWithDefault(f : ((Int) -> Int)? = nil) {}
|
||||
func takeTwoFuncsWithDefaults(f1 : ((Int) -> Int)? = nil, f2 : ((String) -> String)? = nil) {}
|
||||
|
||||
struct X {
|
||||
func takeFunc(_ f: (Int) -> Int) {}
|
||||
func takeValueAndFunc(_ value: Int, f: (Int) -> Int) {}
|
||||
func takeTwoFuncs(_ f: (Int) -> Int, g: (Int) -> Int) {}
|
||||
}
|
||||
|
||||
func addToMemberCalls(_ x: X) {
|
||||
x.takeFunc() { x in x }
|
||||
x.takeFunc() { $0 }
|
||||
x.takeValueAndFunc(1) { x in x }
|
||||
x.takeTwoFuncs({ x in x }) { y in y }
|
||||
}
|
||||
|
||||
func addToCalls() {
|
||||
takeFunc() { x in x }
|
||||
takeFunc() { $0 }
|
||||
takeValueAndFunc(1) { x in x }
|
||||
takeTwoFuncs({ x in x }) { y in y }
|
||||
}
|
||||
|
||||
func makeCalls() {
|
||||
takeFunc { x in x }
|
||||
takeFunc { $0 }
|
||||
takeTwoFuncs ({ x in x }) { y in y }
|
||||
}
|
||||
|
||||
func notPostfix() {
|
||||
_ = 1 + takeFunc { $0 }
|
||||
}
|
||||
|
||||
func notLiterals() {
|
||||
struct SR3671 { // <https://bugs.swift.org/browse/SR-3671>
|
||||
var v: Int = 1 { // expected-error {{variable with getter/setter cannot have an initial value}}
|
||||
get {
|
||||
return self.v
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var x: Int? = nil { get { } } // expected-error {{variable with getter/setter cannot have an initial value}}
|
||||
_ = 1 {}
|
||||
// expected-error@-1 {{consecutive statements on a line must be separated by ';'}}
|
||||
// expected-error@-2 {{closure expression is unused}} expected-note@-2 {{did you mean to use a 'do' statement?}} {{9-9=do }}
|
||||
_ = "hello" {}
|
||||
// expected-error@-1 {{consecutive statements on a line must be separated by ';'}}
|
||||
// expected-error@-2 {{closure expression is unused}} expected-note@-2 {{did you mean to use a 'do' statement?}} {{15-15=do }}
|
||||
_ = [42] {}
|
||||
// expected-error@-1 {{consecutive statements on a line must be separated by ';'}}
|
||||
// expected-error@-2 {{closure expression is unused}} expected-note@-2 {{did you mean to use a 'do' statement?}} {{12-12=do }}
|
||||
_ = (6765, 10946, 17711) {}
|
||||
// expected-error@-1 {{consecutive statements on a line must be separated by ';'}}
|
||||
// expected-error@-2 {{closure expression is unused}} expected-note@-2 {{did you mean to use a 'do' statement?}} {{28-28=do }}
|
||||
}
|
||||
|
||||
class C {
|
||||
func map(_ x: (Int) -> Int) -> C { return self }
|
||||
func filter(_ x: (Int) -> Bool) -> C { return self }
|
||||
}
|
||||
|
||||
var a = C().map {$0 + 1}.filter {$0 % 3 == 0}
|
||||
|
||||
var b = C().map {$0 + 1}
|
||||
.filter {$0 % 3 == 0}
|
||||
|
||||
var c = C().map
|
||||
{
|
||||
$0 + 1
|
||||
}
|
||||
|
||||
var c2 = C().map // expected-note{{callee is here}}
|
||||
|
||||
{ // expected-warning{{braces here form a trailing closure separated from its callee by multiple newlines}}
|
||||
$0 + 1
|
||||
}
|
||||
|
||||
var c3 = C().map // expected-note{{callee is here}}
|
||||
// blah blah blah
|
||||
{ // expected-warning{{braces here form a trailing closure separated from its callee by multiple newlines}}
|
||||
$0 + 1
|
||||
}
|
||||
|
||||
// Calls with multiple trailing closures should be rejected until we have time
|
||||
// to design it right.
|
||||
// <rdar://problem/16835718> Ban multiple trailing closures
|
||||
func multiTrailingClosure(_ a : () -> (), b : () -> ()) { // expected-note {{'multiTrailingClosure(_:b:)' declared here}}
|
||||
multiTrailingClosure({}) {} // ok
|
||||
multiTrailingClosure {} {} // expected-error {{missing argument for parameter #1 in call}} expected-error {{consecutive statements on a line must be separated by ';'}} {{26-26=;}} expected-error {{closure expression is unused}} expected-note{{did you mean to use a 'do' statement?}} {{27-27=do }}
|
||||
|
||||
|
||||
}
|
||||
|
||||
func labeledArgumentAndTrailingClosure() {
|
||||
// Trailing closures can bind to labeled parameters.
|
||||
takeFuncWithDefault { $0 + 1 }
|
||||
takeFuncWithDefault() { $0 + 1 }
|
||||
// ... but not non-trailing closures.
|
||||
takeFuncWithDefault({ $0 + 1 }) // expected-error {{missing argument label 'f:' in call}} {{23-23=f: }}
|
||||
takeFuncWithDefault(f: { $0 + 1 })
|
||||
|
||||
// Trailing closure binds to last parameter, always.
|
||||
takeTwoFuncsWithDefaults { "Hello, " + $0 }
|
||||
takeTwoFuncsWithDefaults { $0 + 1 } // expected-error {{cannot convert value of type '(Int) -> Int' to expected argument type '((String) -> String)?'}}
|
||||
takeTwoFuncsWithDefaults(f1: {$0 + 1 })
|
||||
}
|
||||
|
||||
// rdar://problem/17965209
|
||||
func rdar17965209_f<T>(_ t: T) {}
|
||||
func rdar17965209(x: Int = 0, _ handler: (_ y: Int) -> ()) {}
|
||||
func rdar17965209_test() {
|
||||
rdar17965209() {
|
||||
(y) -> () in
|
||||
rdar17965209_f(1)
|
||||
}
|
||||
|
||||
rdar17965209(x: 5) {
|
||||
(y) -> () in
|
||||
rdar17965209_f(1)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// <rdar://problem/22298549> QoI: Unwanted trailing closure produces weird error
|
||||
func limitXY(_ xy:Int, toGamut gamut: [Int]) {}
|
||||
let someInt = 0
|
||||
let intArray = [someInt]
|
||||
limitXY(someInt, toGamut: intArray) {} // expected-error {{extra argument 'toGamut' in call}}
|
||||
|
||||
|
||||
// <rdar://problem/23036383> QoI: Invalid trailing closures in stmt-conditions produce lowsy diagnostics
|
||||
func retBool(x: () -> Int) -> Bool {}
|
||||
func maybeInt(_: () -> Int) -> Int? {}
|
||||
class Foo23036383 {
|
||||
init() {}
|
||||
func map(_: (Int) -> Int) -> Int? {}
|
||||
func meth1(x: Int, _: () -> Int) -> Bool {}
|
||||
func meth2(_: Int, y: () -> Int) -> Bool {}
|
||||
func filter(by: (Int) -> Bool) -> [Int] {}
|
||||
}
|
||||
enum MyErr : Error {
|
||||
case A
|
||||
}
|
||||
|
||||
func r23036383(foo: Foo23036383?, obj: Foo23036383) {
|
||||
|
||||
if retBool(x: { 1 }) { } // OK
|
||||
if (retBool { 1 }) { } // OK
|
||||
|
||||
if retBool{ 1 } { // expected-error {{trailing closure requires parentheses for disambiguation in this context}} {{13-13=(x: }} {{18-18=)}}
|
||||
}
|
||||
if retBool { 1 } { // expected-error {{trailing closure requires parentheses for disambiguation in this context}} {{13-14=(x: }} {{19-19=)}}
|
||||
}
|
||||
if retBool() { 1 } { // expected-error {{trailing closure requires parentheses for disambiguation in this context}} {{14-16=x: }} {{21-21=)}}
|
||||
} else if retBool( ) { 0 } { // expected-error {{trailing closure requires parentheses for disambiguation in this context}} {{21-24=x: }} {{29-29=)}}
|
||||
}
|
||||
|
||||
if let _ = maybeInt { 1 } { // expected-error {{trailing closure requires parentheses for disambiguation in this context}} {{22-23=(}} {{28-28=)}}
|
||||
}
|
||||
if let _ = maybeInt { 1 } , true { // expected-error {{trailing closure requires parentheses for disambiguation in this context}} {{22-23=(}} {{28-28=)}}
|
||||
}
|
||||
|
||||
if let _ = foo?.map {$0+1} { // expected-error {{trailing closure requires parentheses for disambiguation in this context}} {{22-23=(}} {{29-29=)}}
|
||||
}
|
||||
if let _ = foo?.map() {$0+1} { // expected-error {{trailing closure requires parentheses for disambiguation in this context}} {{23-25=}} {{31-31=)}}
|
||||
}
|
||||
if let _ = foo, retBool { 1 } { // expected-error {{trailing closure requires parentheses for disambiguation in this context}} {{26-27=(x: }} {{32-32=)}}
|
||||
}
|
||||
|
||||
if obj.meth1(x: 1) { 0 } { // expected-error {{trailing closure requires parentheses for disambiguation in this context}} {{20-22=, }} {{27-27=)}}
|
||||
}
|
||||
if obj.meth2(1) { 0 } { // expected-error {{trailing closure requires parentheses for disambiguation in this context}} {{17-19=, y: }} {{24-24=)}}
|
||||
}
|
||||
|
||||
for _ in obj.filter {$0 > 4} { // expected-error {{trailing closure requires parentheses for disambiguation in this context}} {{22-23=(by: }} {{31-31=)}}
|
||||
}
|
||||
for _ in obj.filter {$0 > 4} where true { // expected-error {{trailing closure requires parentheses for disambiguation in this context}} {{22-23=(by: }} {{31-31=)}}
|
||||
}
|
||||
for _ in [1,2] where retBool { 1 } { // expected-error {{trailing closure requires parentheses for disambiguation in this context}} {{31-32=(x: }} {{37-37=)}}
|
||||
}
|
||||
|
||||
while retBool { 1 } { // expected-error {{trailing closure requires parentheses for disambiguation in this context}} {{16-17=(x: }} {{22-22=)}}
|
||||
}
|
||||
while let _ = foo, retBool { 1 } { // expected-error {{trailing closure requires parentheses for disambiguation in this context}} {{29-30=(x: }} {{35-35=)}}
|
||||
}
|
||||
|
||||
switch retBool { return 1 } { // expected-error {{trailing closure requires parentheses for disambiguation in this context}} {{17-18=(x: }} {{30-30=)}}
|
||||
default: break
|
||||
}
|
||||
|
||||
do {
|
||||
throw MyErr.A;
|
||||
} catch MyErr.A where retBool { 1 } { // expected-error {{trailing closure requires parentheses for disambiguation in this context}} {{32-33=(x: }} {{38-38=)}}
|
||||
} catch { }
|
||||
|
||||
if let _ = maybeInt { 1 }, retBool { 1 } { }
|
||||
// expected-error@-1 {{trailing closure requires parentheses for disambiguation in this context}} {{22-23=(}} {{28-28=)}}
|
||||
// expected-error@-2 {{trailing closure requires parentheses for disambiguation in this context}} {{37-38=(x: }} {{43-43=)}}
|
||||
}
|
||||
|
||||
func overloadOnLabel(a: () -> Void) {}
|
||||
func overloadOnLabel(b: () -> Void) {}
|
||||
func overloadOnLabel(c: () -> Void) {}
|
||||
|
||||
func overloadOnLabel2(a: () -> Void) {}
|
||||
func overloadOnLabel2(_: () -> Void) {}
|
||||
|
||||
func overloadOnLabelArgs(_: Int, a: () -> Void) {}
|
||||
func overloadOnLabelArgs(_: Int, b: () -> Void) {}
|
||||
|
||||
func overloadOnLabelArgs2(_: Int, a: () -> Void) {}
|
||||
func overloadOnLabelArgs2(_: Int, _: () -> Void) {}
|
||||
|
||||
func overloadOnLabelDefaultArgs(x: Int = 0, a: () -> Void) {}
|
||||
func overloadOnLabelDefaultArgs(x: Int = 1, b: () -> Void) {}
|
||||
|
||||
func overloadOnLabelSomeDefaultArgs(_: Int, x: Int = 0, a: () -> Void) {}
|
||||
func overloadOnLabelSomeDefaultArgs(_: Int, x: Int = 1, b: () -> Void) {}
|
||||
|
||||
func overloadOnDefaultArgsOnly(x: Int = 0, a: () -> Void) {} // expected-note 2 {{found this candidate}}
|
||||
func overloadOnDefaultArgsOnly(y: Int = 1, a: () -> Void) {} // expected-note 2 {{found this candidate}}
|
||||
|
||||
func overloadOnDefaultArgsOnly2(x: Int = 0, a: () -> Void) {} // expected-note 2 {{found this candidate}}
|
||||
func overloadOnDefaultArgsOnly2(y: Bool = true, a: () -> Void) {} // expected-note 2 {{found this candidate}}
|
||||
|
||||
func overloadOnDefaultArgsOnly3(x: Int = 0, a: () -> Void) {} // expected-note 2 {{found this candidate}}
|
||||
func overloadOnDefaultArgsOnly3(x: Bool = true, a: () -> Void) {} // expected-note 2 {{found this candidate}}
|
||||
|
||||
func overloadOnSomeDefaultArgsOnly(_: Int, x: Int = 0, a: () -> Void) {} // expected-note {{found this candidate}}
|
||||
func overloadOnSomeDefaultArgsOnly(_: Int, y: Int = 1, a: () -> Void) {} // expected-note {{found this candidate}}
|
||||
|
||||
func overloadOnSomeDefaultArgsOnly2(_: Int, x: Int = 0, a: () -> Void) {} // expected-note {{found this candidate}}
|
||||
func overloadOnSomeDefaultArgsOnly2(_: Int, y: Bool = true, a: () -> Void) {} // expected-note {{found this candidate}}
|
||||
|
||||
func overloadOnSomeDefaultArgsOnly3(_: Int, x: Int = 0, a: () -> Void) {} // expected-note {{found this candidate}}
|
||||
func overloadOnSomeDefaultArgsOnly3(_: Int, x: Bool = true, a: () -> Void) {} // expected-note {{found this candidate}}
|
||||
|
||||
func testOverloadAmbiguity() {
|
||||
overloadOnLabel {} // expected-error {{ambiguous use of 'overloadOnLabel'}} expected-note {{use an explicit argument label instead of a trailing closure to call 'overloadOnLabel(a:)'}} {{18-19=(a: }} {{21-21=)}} expected-note {{use an explicit argument label instead of a trailing closure to call 'overloadOnLabel(b:)'}} {{18-19=(b: }} {{21-21=)}} expected-note {{use an explicit argument label instead of a trailing closure to call 'overloadOnLabel(c:)'}} {{18-19=(c: }} {{21-21=)}}
|
||||
overloadOnLabel() {} // expected-error {{ambiguous use of 'overloadOnLabel'}} expected-note {{use an explicit argument label instead of a trailing closure to call 'overloadOnLabel(a:)'}} {{19-21=a: }} {{23-23=)}} expected-note {{use an explicit argument label instead of a trailing closure to call 'overloadOnLabel(b:)'}} {{19-21=b: }} {{23-23=)}} expected-note {{use an explicit argument label instead of a trailing closure to call 'overloadOnLabel(c:)'}} {{19-21=c: }} {{23-23=)}}
|
||||
overloadOnLabel2 {} // expected-error {{ambiguous use of 'overloadOnLabel2'}} expected-note {{use an explicit argument label instead of a trailing closure to call 'overloadOnLabel2(a:)'}} {{19-20=(a: }} {{22-22=)}} expected-note {{avoid using a trailing closure to call 'overloadOnLabel2'}} {{19-20=(}} {{22-22=)}}
|
||||
overloadOnLabel2() {} // expected-error {{ambiguous use of 'overloadOnLabel2'}} expected-note {{use an explicit argument label instead of a trailing closure to call 'overloadOnLabel2(a:)'}} {{20-22=a: }} {{24-24=)}} expected-note {{avoid using a trailing closure to call 'overloadOnLabel2'}} {{20-22=}} {{24-24=)}}
|
||||
overloadOnLabelArgs(1) {} // expected-error {{ambiguous use of 'overloadOnLabelArgs'}} expected-note {{use an explicit argument label instead of a trailing closure to call 'overloadOnLabelArgs(_:a:)'}} {{24-26=, a: }} {{28-28=)}} expected-note {{use an explicit argument label instead of a trailing closure to call 'overloadOnLabelArgs(_:b:)'}} {{24-26=, b: }} {{28-28=)}}
|
||||
overloadOnLabelArgs2(1) {} // expected-error {{ambiguous use of 'overloadOnLabelArgs2'}} expected-note {{use an explicit argument label instead of a trailing closure to call 'overloadOnLabelArgs2(_:a:)'}} {{25-27=, a: }} {{29-29=)}} expected-note {{avoid using a trailing closure to call 'overloadOnLabelArgs2'}} {{25-27=, }} {{29-29=)}}
|
||||
overloadOnLabelDefaultArgs {} // expected-error {{ambiguous use of 'overloadOnLabelDefaultArgs'}} expected-note {{use an explicit argument label instead of a trailing closure to call 'overloadOnLabelDefaultArgs(x:a:)'}} {{29-30=(a: }} {{32-32=)}} expected-note {{use an explicit argument label instead of a trailing closure to call 'overloadOnLabelDefaultArgs(x:b:)'}} {{29-30=(b: }} {{32-32=)}}
|
||||
overloadOnLabelDefaultArgs() {} // expected-error {{ambiguous use of 'overloadOnLabelDefaultArgs'}} expected-note {{use an explicit argument label instead of a trailing closure to call 'overloadOnLabelDefaultArgs(x:a:)'}} {{30-32=a: }} {{34-34=)}} expected-note {{use an explicit argument label instead of a trailing closure to call 'overloadOnLabelDefaultArgs(x:b:)'}} {{30-32=b: }} {{34-34=)}}
|
||||
overloadOnLabelDefaultArgs(x: 2) {} // expected-error {{ambiguous use of 'overloadOnLabelDefaultArgs'}} expected-note {{use an explicit argument label instead of a trailing closure to call 'overloadOnLabelDefaultArgs(x:a:)'}} {{34-36=, a: }} {{38-38=)}} expected-note {{use an explicit argument label instead of a trailing closure to call 'overloadOnLabelDefaultArgs(x:b:)'}} {{34-36=, b: }} {{38-38=)}}
|
||||
overloadOnLabelSomeDefaultArgs(1) {} // expected-error {{ambiguous use of 'overloadOnLabelSomeDefaultArgs'}} expected-note {{use an explicit argument label instead of a trailing closure to call 'overloadOnLabelSomeDefaultArgs(_:x:a:)'}} {{35-37=, a: }} {{39-39=)}} expected-note {{use an explicit argument label instead of a trailing closure to call 'overloadOnLabelSomeDefaultArgs(_:x:b:)'}} {{35-37=, b: }} {{39-39=)}}
|
||||
overloadOnLabelSomeDefaultArgs(1, x: 2) {} // expected-error {{ambiguous use of 'overloadOnLabelSomeDefaultArgs'}} expected-note {{use an explicit argument label instead of a trailing closure to call 'overloadOnLabelSomeDefaultArgs(_:x:a:)'}} {{41-43=, a: }} {{45-45=)}} expected-note {{use an explicit argument label instead of a trailing closure to call 'overloadOnLabelSomeDefaultArgs(_:x:b:)'}} {{41-43=, b: }} {{45-45=)}}
|
||||
|
||||
overloadOnLabelSomeDefaultArgs( // expected-error {{ambiguous use of 'overloadOnLabelSomeDefaultArgs'}} expected-note {{use an explicit argument label instead of a trailing closure to call 'overloadOnLabelSomeDefaultArgs(_:x:a:)'}} {{12-5=, a: }} {{4-4=)}} expected-note {{use an explicit argument label instead of a trailing closure to call 'overloadOnLabelSomeDefaultArgs(_:x:b:)'}} {{12-5=, b: }} {{4-4=)}}
|
||||
1, x: 2
|
||||
) {
|
||||
// some
|
||||
}
|
||||
|
||||
overloadOnDefaultArgsOnly {} // expected-error {{ambiguous use of 'overloadOnDefaultArgsOnly'}}
|
||||
overloadOnDefaultArgsOnly() {} // expected-error {{ambiguous use of 'overloadOnDefaultArgsOnly'}}
|
||||
overloadOnDefaultArgsOnly2 {} // expected-error {{ambiguous use of 'overloadOnDefaultArgsOnly2'}}
|
||||
overloadOnDefaultArgsOnly2() {} // expected-error {{ambiguous use of 'overloadOnDefaultArgsOnly2'}}
|
||||
overloadOnDefaultArgsOnly3 {} // expected-error {{ambiguous use of 'overloadOnDefaultArgsOnly3(x:a:)'}}
|
||||
overloadOnDefaultArgsOnly3() {} // expected-error {{ambiguous use of 'overloadOnDefaultArgsOnly3(x:a:)'}}
|
||||
|
||||
overloadOnSomeDefaultArgsOnly(1) {} // expected-error {{ambiguous use of 'overloadOnSomeDefaultArgsOnly'}}
|
||||
overloadOnSomeDefaultArgsOnly2(1) {} // expected-error {{ambiguous use of 'overloadOnSomeDefaultArgsOnly2'}}
|
||||
overloadOnSomeDefaultArgsOnly3(1) {} // expected-error {{ambiguous use of 'overloadOnSomeDefaultArgsOnly3(_:x:a:)'}}
|
||||
}
|
||||
|
||||
func overloadMismatch(a: () -> Void) -> Bool { return true}
|
||||
func overloadMismatch(x: Int = 0, a: () -> Void) -> Int { return 0 }
|
||||
|
||||
func overloadMismatchLabel(a: () -> Void) -> Bool { return true}
|
||||
func overloadMismatchLabel(x: Int = 0, b: () -> Void) -> Int { return 0 }
|
||||
|
||||
func overloadMismatchArgs(_: Int, a: () -> Void) -> Bool { return true}
|
||||
func overloadMismatchArgs(_: Int, x: Int = 0, a: () -> Void) -> Int { return 0 }
|
||||
|
||||
func overloadMismatchArgsLabel(_: Int, a: () -> Void) -> Bool { return true}
|
||||
func overloadMismatchArgsLabel(_: Int, x: Int = 0, b: () -> Void) -> Int { return 0 }
|
||||
|
||||
func overloadMismatchMultiArgs(_: Int, a: () -> Void) -> Bool { return true}
|
||||
func overloadMismatchMultiArgs(_: Int, x: Int = 0, y: Int = 1, a: () -> Void) -> Int { return 0 }
|
||||
|
||||
func overloadMismatchMultiArgsLabel(_: Int, a: () -> Void) -> Bool { return true}
|
||||
func overloadMismatchMultiArgsLabel(_: Int, x: Int = 0, y: Int = 1, b: () -> Void) -> Int { return 0 }
|
||||
|
||||
func overloadMismatchMultiArgs2(_: Int, z: Int = 0, a: () -> Void) -> Bool { return true}
|
||||
func overloadMismatchMultiArgs2(_: Int, x: Int = 0, y: Int = 1, a: () -> Void) -> Int { return 0 }
|
||||
|
||||
func overloadMismatchMultiArgs2Label(_: Int, z: Int = 0, a: () -> Void) -> Bool { return true}
|
||||
func overloadMismatchMultiArgs2Label(_: Int, x: Int = 0, y: Int = 1, b: () -> Void) -> Int { return 0 }
|
||||
|
||||
func testOverloadDefaultArgs() {
|
||||
let a = overloadMismatch {}
|
||||
_ = a as String // expected-error {{cannot convert value of type 'Bool' to type 'String' in coercion}}
|
||||
let b = overloadMismatch() {}
|
||||
_ = b as String // expected-error {{cannot convert value of type 'Bool' to type 'String' in coercion}}
|
||||
|
||||
let c = overloadMismatchLabel {}
|
||||
_ = c as String // expected-error {{cannot convert value of type 'Bool' to type 'String' in coercion}}
|
||||
let d = overloadMismatchLabel() {}
|
||||
_ = d as String // expected-error {{cannot convert value of type 'Bool' to type 'String' in coercion}}
|
||||
|
||||
let e = overloadMismatchArgs(0) {}
|
||||
_ = e as String // expected-error {{cannot convert value of type 'Bool' to type 'String' in coercion}}
|
||||
|
||||
let f = overloadMismatchArgsLabel(0) {}
|
||||
_ = f as String // expected-error {{cannot convert value of type 'Bool' to type 'String' in coercion}}
|
||||
|
||||
let g = overloadMismatchMultiArgs(0) {}
|
||||
_ = g as String // expected-error {{cannot convert value of type 'Bool' to type 'String' in coercion}}
|
||||
|
||||
let h = overloadMismatchMultiArgsLabel(0) {}
|
||||
_ = h as String // expected-error {{cannot convert value of type 'Bool' to type 'String' in coercion}}
|
||||
|
||||
let i = overloadMismatchMultiArgs2(0) {}
|
||||
_ = i as String // expected-error {{cannot convert value of type 'Bool' to type 'String' in coercion}}
|
||||
|
||||
let j = overloadMismatchMultiArgs2Label(0) {}
|
||||
_ = j as String // expected-error {{cannot convert value of type 'Bool' to type 'String' in coercion}}
|
||||
}
|
||||
|
||||
func variadic(_: (() -> Void)...) {}
|
||||
func variadicLabel(closures: (() -> Void)...) {}
|
||||
|
||||
func variadicOverloadMismatch(_: (() -> Void)...) -> Bool { return true }
|
||||
func variadicOverloadMismatch(x: Int = 0, _: (() -> Void)...) -> Int { return 0 }
|
||||
|
||||
func variadicOverloadMismatchLabel(a: (() -> Void)...) -> Bool { return true }
|
||||
func variadicOverloadMismatchLabel(x: Int = 0, b: (() -> Void)...) -> Int { return 0 }
|
||||
|
||||
func variadicAndNonOverload(_: (() -> Void)) -> Bool { return false }
|
||||
func variadicAndNonOverload(_: (() -> Void)...) -> Int { return 0 }
|
||||
|
||||
func variadicAndNonOverloadLabel(a: (() -> Void)) -> Bool { return false }
|
||||
func variadicAndNonOverloadLabel(b: (() -> Void)...) -> Int { return 0 }
|
||||
|
||||
func testVariadic() {
|
||||
variadic {}
|
||||
variadic() {}
|
||||
variadic({}) {} // expected-error {{extra argument in call}}
|
||||
|
||||
variadicLabel {}
|
||||
variadicLabel() {}
|
||||
variadicLabel(closures: {}) {} // expected-error {{extra argument 'closures' in call}}
|
||||
|
||||
let a1 = variadicOverloadMismatch {}
|
||||
_ = a1 as String // expected-error {{cannot convert value of type 'Bool' to type 'String' in coercion}}
|
||||
let a2 = variadicOverloadMismatch() {}
|
||||
_ = a2 as String // expected-error {{cannot convert value of type 'Bool' to type 'String' in coercion}}
|
||||
|
||||
let b1 = variadicOverloadMismatchLabel {}
|
||||
_ = b1 as String // expected-error {{cannot convert value of type 'Bool' to type 'String' in coercion}}
|
||||
let b2 = variadicOverloadMismatchLabel() {}
|
||||
_ = b2 as String // expected-error {{cannot convert value of type 'Bool' to type 'String' in coercion}}
|
||||
|
||||
let c1 = variadicAndNonOverloadLabel {}
|
||||
_ = c1 as String // expected-error {{cannot convert value of type 'Bool' to type 'String'}}
|
||||
|
||||
let c2 = variadicAndNonOverload {}
|
||||
_ = c2 as String // expected-error {{cannot convert value of type 'Bool' to type 'String'}}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,37 +0,0 @@
|
||||
// RUN: %target-typecheck-verify-swift -swift-version 3
|
||||
|
||||
func takesOneArg<T>(_: T.Type) {}
|
||||
func takesTwoArgs<T>(_: T.Type, _: Int) {}
|
||||
|
||||
func testMissingSelf() {
|
||||
// None of these were not caught in Swift 3.
|
||||
// See test/Compatibility/type_expr.swift.
|
||||
|
||||
takesOneArg(Int)
|
||||
// expected-warning@-1 {{missing '.self' for reference to metatype of type 'Int'}}
|
||||
|
||||
takesOneArg(Swift.Int)
|
||||
// expected-warning@-1 {{missing '.self' for reference to metatype of type 'Int'}}
|
||||
|
||||
takesTwoArgs(Int, 0)
|
||||
// expected-warning@-1 {{missing '.self' for reference to metatype of type 'Int'}}
|
||||
|
||||
takesTwoArgs(Swift.Int, 0)
|
||||
// expected-warning@-1 {{missing '.self' for reference to metatype of type 'Int'}}
|
||||
|
||||
Swift.Int // expected-warning {{expression of type 'Int.Type' is unused}}
|
||||
// expected-warning@-1 {{missing '.self' for reference to metatype of type 'Int'}}
|
||||
|
||||
_ = Swift.Int
|
||||
// expected-warning@-1 {{missing '.self' for reference to metatype of type 'Int'}}
|
||||
|
||||
Int // expected-warning {{expression of type 'Int.Type' is unused}}
|
||||
// expected-error@-1 {{expected member name or constructor call after type name}}
|
||||
// expected-note@-2 {{add arguments after the type to construct a value of the type}}
|
||||
// expected-note@-3 {{use '.self' to reference the type object}}
|
||||
|
||||
_ = Int
|
||||
// expected-error@-1 {{expected member name or constructor call after type name}}
|
||||
// expected-note@-2 {{add arguments after the type to construct a value of the type}}
|
||||
// expected-note@-3 {{use '.self' to reference the type object}}
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
// RUN: %target-typecheck-verify-swift -swift-version 3
|
||||
|
||||
class Foo { }
|
||||
|
||||
// Complain about unavailable witnesses (error in Swift 4, warning in Swift 3)
|
||||
protocol P {
|
||||
func foo(bar: Foo) // expected-note{{requirement 'foo(bar:)' declared here}}
|
||||
}
|
||||
|
||||
struct ConformsToP : P {
|
||||
@available(*, unavailable)
|
||||
func foo(bar: Foo) { } // expected-warning{{unavailable instance method 'foo(bar:)' was used to satisfy a requirement of protocol 'P'}}
|
||||
}
|
||||
|
||||
@@ -1,21 +0,0 @@
|
||||
// RUN: %target-typecheck-verify-swift -swift-version 3
|
||||
|
||||
// Stupid Swift 3 unqualified lookup quirk
|
||||
|
||||
func f3(_ x: Int, _ y: Int, z: Int) { } // expected-note{{did you mean 'f3'?}}
|
||||
|
||||
struct S0 {
|
||||
func testS0() {
|
||||
_ = f3(_:y:z:) // expected-error{{use of unresolved identifier 'f3(_:y:z:)'}}
|
||||
}
|
||||
|
||||
static func f3(_ x: Int, y: Int, z: Int) -> S0 { return S0() }
|
||||
}
|
||||
|
||||
extension Float {
|
||||
func isClose(to: Float, epiValue: Float = 1e-5) -> Bool {
|
||||
// Float.abs() and Swift.abs() are both visible here, but
|
||||
// Swift 3 drops 'Float.abs()'.
|
||||
return abs(self - to) < epiValue
|
||||
}
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
// RUN: %target-typecheck-verify-swift -swift-version 3
|
||||
|
||||
protocol P {
|
||||
associatedtype A
|
||||
associatedtype B
|
||||
|
||||
func f<T: P>(_: T) where T.A == Self.A, T.A == Self.B // expected-warning{{adding constraint 'Self.A == Self.B' on 'Self' via instance method requirement 'f' is deprecated}}
|
||||
// expected-note@-1{{protocol requires function 'f' with type '<T> (T) -> ()'; do you want to add a stub?}}
|
||||
}
|
||||
|
||||
extension P {
|
||||
func f<T: P>(_: T) where T.A == Self.A, T.A == Self.B { } // expected-note{{candidate has non-matching type '<Self, T> (T) -> ()'}}
|
||||
}
|
||||
|
||||
struct X : P { // expected-error{{type 'X' does not conform to protocol 'P'}}
|
||||
typealias A = X
|
||||
typealias B = Int
|
||||
}
|
||||
|
||||
struct Y : P {
|
||||
typealias A = Y
|
||||
typealias B = Y
|
||||
}
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
// RUN: %target-typecheck-verify-swift -swift-version 3
|
||||
// RUN: %target-typecheck-verify-swift -swift-version 4
|
||||
|
||||
func myMap<T1, T2>(_ array: [T1], _ fn: (T1) -> T2) -> [T2] {}
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
// RUN: %target-typecheck-verify-swift -swift-version 3
|
||||
|
||||
var _: () -> Int = {a in 0}
|
||||
|
||||
var _: (Int, Int) -> Int = {a in 0}
|
||||
|
||||
// <rdar://problem/20371273> Type errors inside anonymous functions don't provide enough information
|
||||
func f20371273() {
|
||||
let x: [Int] = [1, 2, 3, 4]
|
||||
let y: UInt = 4
|
||||
_ = x.filter { ($0 + y) > 42 } // expected-warning {{deprecated}}
|
||||
}
|
||||
|
||||
// rdar://problem/32432145 - compiler should emit fixit to remove "_ in" in closures if 0 parameters is expected
|
||||
|
||||
func r32432145(_ a: () -> ()) {}
|
||||
r32432145 { _ in let _ = 42 } // Ok in Swift 3
|
||||
r32432145 { _ in // Ok in Swift 3
|
||||
print("answer is 42")
|
||||
}
|
||||
@@ -1,4 +1,3 @@
|
||||
// RUN: %target-typecheck-verify-swift -swift-version 3
|
||||
// RUN: %target-typecheck-verify-swift -swift-version 4
|
||||
|
||||
// rdar://problem/31969605
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
// RUN: %target-swift-frontend -module-name main -typecheck -verify -swift-version 3 %s
|
||||
// RUN: %target-swift-frontend -module-name main -typecheck -verify -swift-version 4 %s
|
||||
|
||||
// Some convenient test points to escape closures to
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
// RUN: %target-swift-frontend -module-name main -typecheck -swift-version 3 %s
|
||||
// RUN: %target-swift-frontend -module-name main -typecheck -swift-version 4 %s
|
||||
|
||||
// These tests are split out to ensure that we run the AST verifier's
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
// RUN: %target-typecheck-verify-swift -swift-version 3
|
||||
// RUN: %target-typecheck-verify-swift -swift-version 4
|
||||
|
||||
extension Sequence where Element: AnyObject {
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
// RUN: %target-swift-frontend %s -swift-version 4 -emit-ir -enforce-exclusivity=checked | %FileCheck --check-prefix=CHECK --check-prefix=CHECK-SWIFT4 --check-prefix=CHECK-%target-cpu %s
|
||||
// RUN: %target-swift-frontend %s -swift-version 3 -emit-ir -enforce-exclusivity=checked | %FileCheck --check-prefix=CHECK --check-prefix=CHECK-SWIFT3 --check-prefix=CHECK-%target-cpu %s
|
||||
// RUN: %target-swift-frontend %s -swift-version 4 -emit-ir -enforce-exclusivity=checked | %FileCheck --check-prefix=CHECK --check-prefix=CHECK-%target-cpu %s
|
||||
|
||||
sil_stage canonical
|
||||
|
||||
@@ -25,8 +24,7 @@ bb0(%0 : $A):
|
||||
// CHECK: [[T0:%.*]] = bitcast [[BUFFER_T]]* [[SCRATCH0]] to i8*
|
||||
// CHECK: call void @llvm.lifetime.start.p0i8(i64 -1, i8* [[T0]])
|
||||
// CHECK: [[T0:%.*]] = bitcast [[INT:%TSi]]* [[PROP]] to i8*
|
||||
// CHECK-SWIFT3: call void @swift_beginAccess(i8* [[T0]], [[BUFFER_T]]* [[SCRATCH0]], [[SIZE_T:i32|i64]] 48, i8* null)
|
||||
// CHECK-SWIFT4: call void @swift_beginAccess(i8* [[T0]], [[BUFFER_T]]* [[SCRATCH0]], [[SIZE_T:i32|i64]] 32, i8* null)
|
||||
// CHECK: call void @swift_beginAccess(i8* [[T0]], [[BUFFER_T]]* [[SCRATCH0]], [[SIZE_T:i32|i64]] 32, i8* null)
|
||||
%4 = begin_access [read] [dynamic] %3 : $*Int
|
||||
|
||||
// CHECK: [[T0:%.*]] = getelementptr inbounds [[INT]], [[INT]]* %1, i32 0, i32 0
|
||||
@@ -46,8 +44,7 @@ bb0(%0 : $A):
|
||||
// CHECK: [[T0:%.*]] = bitcast [[BUFFER_T]]* [[SCRATCH1]] to i8*
|
||||
// CHECK: call void @llvm.lifetime.start.p0i8(i64 -1, i8* [[T0]])
|
||||
// CHECK: [[T0:%.*]] = bitcast [[INT:%TSi]]* [[PROP]] to i8*
|
||||
// CHECK-SWIFT3: call void @swift_beginAccess(i8* [[T0]], [[BUFFER_T]]* [[SCRATCH1]], [[SIZE_T:i32|i64]] 49, i8* null)
|
||||
// CHECK-SWIFT4: call void @swift_beginAccess(i8* [[T0]], [[BUFFER_T]]* [[SCRATCH1]], [[SIZE_T:i32|i64]] 33, i8* null)
|
||||
// CHECK: call void @swift_beginAccess(i8* [[T0]], [[BUFFER_T]]* [[SCRATCH1]], [[SIZE_T:i32|i64]] 33, i8* null)
|
||||
%12 = begin_access [modify] [dynamic] %11 : $*Int
|
||||
|
||||
// CHECK: call {{.*}} @changeInt([[INT]]*{{.*}} [[PROP]])
|
||||
|
||||
@@ -1,22 +0,0 @@
|
||||
// RUN: %target-swift-frontend -emit-ir %s -swift-version 3
|
||||
|
||||
// rdar://29605388 -- Swift 3 admitted opening an existential type with
|
||||
// associated types in one case.
|
||||
|
||||
protocol HasAssoc {
|
||||
associatedtype A
|
||||
}
|
||||
|
||||
enum MyError : Error {
|
||||
case bad(Any)
|
||||
}
|
||||
|
||||
func checkIt(_ js: Any) throws {
|
||||
switch js {
|
||||
case let dbl as HasAssoc:
|
||||
throw MyError.bad(dbl)
|
||||
|
||||
default:
|
||||
fatalError("wrong")
|
||||
}
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
// RUN: %empty-directory(%t)
|
||||
// RUN: %target-swift-frontend -assume-parsing-unqualified-ownership-sil -enable-objc-interop -emit-ir -parse-as-library -swift-version 3 %s | %FileCheck %s
|
||||
|
||||
public func singleDefaultArgument(i: Int = {
|
||||
// CHECK-DAG: @"$S18local_types_swift321singleDefaultArgument1iySi_tFfA_SiycfU_06SingleeF6StructL_VMf" = internal constant
|
||||
struct SingleDefaultArgumentStruct {
|
||||
let i: Int
|
||||
}
|
||||
return 2
|
||||
|
||||
}()){
|
||||
print(i)
|
||||
}
|
||||
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
// RUN: %target-swift-frontend -assume-parsing-unqualified-ownership-sil %s -emit-ir -disable-objc-attr-requires-foundation-module -enable-swift3-objc-inference -swift-version 4 | %FileCheck -check-prefix CHECK-SWIFT4 %s
|
||||
|
||||
// RUN: %target-swift-frontend -assume-parsing-unqualified-ownership-sil %s -emit-ir -disable-objc-attr-requires-foundation-module -swift-version 3 | %FileCheck -check-prefix CHECK-SWIFT3 %s
|
||||
// RUN: %target-swift-frontend -assume-parsing-unqualified-ownership-sil %s -emit-ir -disable-objc-attr-requires-foundation-module -enable-swift3-objc-inference -swift-version 4 | %FileCheck %s
|
||||
|
||||
// REQUIRES: CPU=x86_64
|
||||
// REQUIRES: objc_interop
|
||||
|
||||
// CHECK-SWIFT4: [[FILENAME_STR:@.*]] = private unnamed_addr constant {{.*}}.swift\00"
|
||||
// CHECK: [[FILENAME_STR:@.*]] = private unnamed_addr constant {{.*}}.swift\00"
|
||||
|
||||
import Foundation
|
||||
|
||||
@@ -13,11 +11,7 @@ class ObjCSubclass : NSObject {
|
||||
func foo() { }
|
||||
}
|
||||
|
||||
// CHECK-SWIFT4-LABEL: define hidden void @"$S016objc_deprecated_A7_thunks12ObjCSubclassC3fooyyFTo"(%0*, i8*)
|
||||
// CHECK-SWIFT4: entry:
|
||||
// CHECK-SWIFT4: [[SELF:%[0-9]+]] = bitcast %0* %0 to %objc_object*
|
||||
// CHECK-SWIFT4-NEXT: call void @swift_objc_swift3ImplicitObjCEntrypoint(%objc_object* [[SELF]], i8* %1, i8* getelementptr inbounds ({{.*}}[[FILENAME_STR]]{{.*}}), i64 [[FILENAME_LENGTH:[0-9]+]], i64 13, i64 3, i8* {{.*}})
|
||||
|
||||
// CHECK-SWIFT3-LABEL: define hidden void @"$S016objc_deprecated_A7_thunks12ObjCSubclassC3fooyyFTo"(%0*, i8*)
|
||||
// CHECK-SWIFT3: entry:
|
||||
// CHECK-SWIFT3-NOT: call void @swift_objc_swift3ImplicitObjCEntrypoint
|
||||
// CHECK-LABEL: define hidden void @"$S016objc_deprecated_A7_thunks12ObjCSubclassC3fooyyFTo"(%0*, i8*)
|
||||
// CHECK: entry:
|
||||
// CHECK: [[SELF:%[0-9]+]] = bitcast %0* %0 to %objc_object*
|
||||
// CHECK-NEXT: call void @swift_objc_swift3ImplicitObjCEntrypoint(%objc_object* [[SELF]], i8* %1, i8* getelementptr inbounds ({{.*}}[[FILENAME_STR]]{{.*}}), i64 [[FILENAME_LENGTH:[0-9]+]], i64 11, i64 3, i8* {{.*}})
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
// RUN: %target-swift-frontend -swift-version 3 -parse-stdlib -Xllvm -sil-disable-pass=FunctionSignatureOpts -Xllvm -sil-disable-pass=GenericSpecializer -emit-ir -O %s | %FileCheck %s
|
||||
// RUN: %target-swift-frontend -swift-version 4 -parse-stdlib -Xllvm -sil-disable-pass=FunctionSignatureOpts -Xllvm -sil-disable-pass=GenericSpecializer -emit-ir -O %s | %FileCheck %s
|
||||
//
|
||||
// Check that the -O pipeline always preserves the runtime calls for Builtin access markers and that the KeyPath implementation is fully inlined.
|
||||
|
||||
@@ -1,26 +0,0 @@
|
||||
|
||||
// RUN: %target-swift-emit-silgen -module-name argument_shuffle_swift3 -enable-sil-ownership %s -swift-version 3 | %FileCheck %s
|
||||
|
||||
func fn(_: Any) {}
|
||||
|
||||
enum HasAnyCase {
|
||||
case any(_: Any)
|
||||
}
|
||||
|
||||
// CHECK-LABEL: sil hidden @$S23argument_shuffle_swift31g1xyyp_tF : $@convention(thin) (@in_guaranteed Any) -> () {
|
||||
func g(x: Any) {
|
||||
// CHECK: [[FN:%.*]] = function_ref @$S23argument_shuffle_swift32fnyyypF : $@convention(thin) (@in_guaranteed Any) -> ()
|
||||
// CHECK: apply [[FN:%.*]]({{.*}}) : $@convention(thin) (@in_guaranteed Any) -> ()
|
||||
fn(data: 123)
|
||||
// CHECK: [[FN:%.*]] = function_ref @$S23argument_shuffle_swift32fnyyypF : $@convention(thin) (@in_guaranteed Any) -> ()
|
||||
// CHECK: apply [[FN:%.*]]({{.*}}) : $@convention(thin) (@in_guaranteed Any) -> ()
|
||||
fn(data: x)
|
||||
|
||||
// CHECK: inject_enum_addr {{.*}} : $*HasAnyCase, #HasAnyCase.any!enumelt.1
|
||||
_ = HasAnyCase.any(123)
|
||||
|
||||
// CHECK: inject_enum_addr {{.*}} : $*HasAnyCase, #HasAnyCase.any!enumelt.1
|
||||
_ = HasAnyCase.any(data: 123)
|
||||
|
||||
// CHECK: return
|
||||
}
|
||||
@@ -1,7 +1,4 @@
|
||||
|
||||
// RUN: %target-swift-emit-silgen -module-name default_arguments -Xllvm -sil-full-demangle -enable-sil-ownership -swift-version 3 %s | %FileCheck %s
|
||||
// RUN: %target-swift-emit-silgen -module-name default_arguments -Xllvm -sil-full-demangle -enable-sil-ownership -swift-version 3 %s | %FileCheck %s --check-prefix=NEGATIVE
|
||||
|
||||
// RUN: %target-swift-emit-silgen -module-name default_arguments -Xllvm -sil-full-demangle -enable-sil-ownership -swift-version 4 %s | %FileCheck %s
|
||||
// RUN: %target-swift-emit-silgen -module-name default_arguments -Xllvm -sil-full-demangle -enable-sil-ownership -swift-version 4 %s | %FileCheck %s --check-prefix=NEGATIVE
|
||||
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
|
||||
// RUN: %target-swift-emit-silgen -module-name default_arguments_generic -enable-sil-ownership -swift-version 3 %s | %FileCheck %s
|
||||
// RUN: %target-swift-emit-silgen -module-name default_arguments_generic -enable-sil-ownership -swift-version 4 %s | %FileCheck %s
|
||||
|
||||
func foo<T: ExpressibleByIntegerLiteral>(_: T.Type, x: T = 0) { }
|
||||
|
||||
@@ -2,10 +2,8 @@
|
||||
// RUN: %empty-directory(%t)
|
||||
// RUN: %target-swift-frontend -emit-module-path %t/default_arguments_other.swiftmodule -emit-module -swift-version 4 -primary-file %S/Inputs/default_arguments_other.swift
|
||||
|
||||
// RUN: %target-swift-emit-silgen -module-name default_arguments_serialized -Xllvm -sil-full-demangle -enable-sil-ownership -swift-version 3 -I %t %s | %FileCheck %s --check-prefix=SWIFT3 --check-prefix=CHECK
|
||||
// RUN: %target-swift-emit-silgen -module-name default_arguments_serialized -Xllvm -sil-full-demangle -enable-sil-ownership -swift-version 4 -I %t %s | %FileCheck %s --check-prefix=SWIFT4 --check-prefix=CHECK
|
||||
// RUN: %target-swift-emit-silgen -module-name default_arguments_serialized -Xllvm -sil-full-demangle -enable-sil-ownership -swift-version 4 -I %t %s | %FileCheck %s
|
||||
|
||||
// RUN: %target-swift-emit-sil -module-name default_arguments_serialized -Xllvm -sil-full-demangle -enable-sil-ownership -O -swift-version 3 -I %t %s | %FileCheck %s --check-prefix=OPT
|
||||
// RUN: %target-swift-emit-sil -module-name default_arguments_serialized -Xllvm -sil-full-demangle -enable-sil-ownership -O -swift-version 4 -I %t %s | %FileCheck %s --check-prefix=OPT
|
||||
|
||||
// Check that default arguments are serialized in Swift 4 mode.
|
||||
@@ -15,11 +13,9 @@ import default_arguments_other
|
||||
// CHECK-LABEL: sil @$S28default_arguments_serialized0A6StringSSyF : $@convention(thin) () -> @owned String
|
||||
public func defaultString() -> String { return "hi" }
|
||||
|
||||
// SWIFT3-LABEL: sil @$S28default_arguments_serialized19hasDefaultArguments1x1yySi_SStFfA_ : $@convention(thin) () -> Int
|
||||
// SWIFT4-LABEL: sil non_abi [serialized] @$S28default_arguments_serialized19hasDefaultArguments1x1yySi_SStFfA_ : $@convention(thin) () -> Int
|
||||
// CHECK-LABEL: sil non_abi [serialized] @$S28default_arguments_serialized19hasDefaultArguments1x1yySi_SStFfA_ : $@convention(thin) () -> Int
|
||||
|
||||
// SWIFT3-LABEL: sil @$S28default_arguments_serialized19hasDefaultArguments1x1yySi_SStFfA0_ : $@convention(thin) () -> @owned String
|
||||
// SWIFT4-LABEL: sil non_abi [serialized] @$S28default_arguments_serialized19hasDefaultArguments1x1yySi_SStFfA0_ : $@convention(thin) () -> @owned String
|
||||
// CHECK-LABEL: sil non_abi [serialized] @$S28default_arguments_serialized19hasDefaultArguments1x1yySi_SStFfA0_ : $@convention(thin) () -> @owned String
|
||||
|
||||
public func hasDefaultArguments(x: Int = 0, y: String = defaultString()) {}
|
||||
|
||||
|
||||
@@ -1,64 +0,0 @@
|
||||
// RUN: %target-swift-emit-silgen -swift-version 3 -enable-sil-ownership %s | %FileCheck %s
|
||||
|
||||
enum Downgradable {
|
||||
case spoon
|
||||
case hat
|
||||
@_downgrade_exhaustivity_check
|
||||
case fork
|
||||
}
|
||||
|
||||
// CHECK-LABEL: sil hidden @$S29downgrade_exhaustivity_swift343testDowngradableOmittedPatternIsUnreachable3patyAA0E0OSg_tF
|
||||
func testDowngradableOmittedPatternIsUnreachable(pat : Downgradable?) {
|
||||
// CHECK: switch_enum {{%.*}} : $Downgradable, case #Downgradable.spoon!enumelt: [[CASE1:bb[0-9]+]], case #Downgradable.hat!enumelt: [[CASE2:bb[0-9]+]], default [[DEFAULT_CASE:bb[0-9]+]]
|
||||
switch pat! {
|
||||
// CHECK: [[CASE1]]:
|
||||
case .spoon:
|
||||
break
|
||||
// CHECK: [[CASE2]]:
|
||||
case .hat:
|
||||
break
|
||||
// CHECK: [[DEFAULT_CASE]]({{%.*}} : @trivial $Downgradable):
|
||||
// CHECK-NEXT: [[METATYPE:%.+]] = value_metatype $@thick Downgradable.Type, {{%.*}} : $Downgradable
|
||||
// CHECK-NEXT: // function_ref
|
||||
// CHECK-NEXT: [[DIAGNOSE:%.+]] = function_ref @$Ss27_diagnoseUnexpectedEnumCase
|
||||
// CHECK-NEXT: = apply [[DIAGNOSE]]<Downgradable>([[METATYPE]]) : $@convention(thin) <τ_0_0> (@thick τ_0_0.Type) -> Never
|
||||
// CHECK-NEXT: unreachable
|
||||
}
|
||||
|
||||
// CHECK: switch_enum {{%[0-9]+}} : $Downgradable, case #Downgradable.spoon!enumelt: {{bb[0-9]+}}, case #Downgradable.hat!enumelt: {{bb[0-9]+}}, default [[TUPLE_DEFAULT_CASE_1:bb[0-9]+]]
|
||||
// CHECK: switch_enum [[Y:%[0-9]+]] : $Downgradable, case #Downgradable.spoon!enumelt: {{bb[0-9]+}}, case #Downgradable.hat!enumelt: {{bb[0-9]+}}, default [[TUPLE_DEFAULT_CASE_2:bb[0-9]+]]
|
||||
switch (pat!, pat!) {
|
||||
case (.spoon, .spoon):
|
||||
break
|
||||
case (.spoon, .hat):
|
||||
break
|
||||
case (.hat, .spoon):
|
||||
break
|
||||
case (.hat, .hat):
|
||||
break
|
||||
// CHECK: [[TUPLE_DEFAULT_CASE_2]]({{%.*}} : @trivial $Downgradable):
|
||||
// CHECK-NEXT: [[METATYPE:%.+]] = value_metatype $@thick (Downgradable, Downgradable).Type, {{%.*}} : $(Downgradable, Downgradable)
|
||||
// CHECK-NEXT: // function_ref
|
||||
// CHECK-NEXT: [[DIAGNOSE:%.+]] = function_ref @$Ss27_diagnoseUnexpectedEnumCase
|
||||
// CHECK-NEXT: = apply [[DIAGNOSE]]<(Downgradable, Downgradable)>([[METATYPE]]) : $@convention(thin) <τ_0_0> (@thick τ_0_0.Type) -> Never
|
||||
// CHECK-NEXT: unreachable
|
||||
|
||||
// CHECK: switch_enum [[Y]] : $Downgradable, case #Downgradable.spoon!enumelt: {{bb[0-9]+}}, case #Downgradable.hat!enumelt: {{bb[0-9]+}}, default [[TUPLE_DEFAULT_CASE_3:bb[0-9]+]]
|
||||
|
||||
// CHECK: [[TUPLE_DEFAULT_CASE_3]]({{%.*}} : @trivial $Downgradable):
|
||||
// CHECK-NEXT: [[METATYPE:%.+]] = value_metatype $@thick (Downgradable, Downgradable).Type, {{%.*}} : $(Downgradable, Downgradable)
|
||||
// CHECK-NEXT: // function_ref
|
||||
// CHECK-NEXT: [[DIAGNOSE:%.+]] = function_ref @$Ss27_diagnoseUnexpectedEnumCase
|
||||
// CHECK-NEXT: = apply [[DIAGNOSE]]<(Downgradable, Downgradable)>([[METATYPE]]) : $@convention(thin) <τ_0_0> (@thick τ_0_0.Type) -> Never
|
||||
// CHECK-NEXT: unreachable
|
||||
|
||||
// CHECK: [[TUPLE_DEFAULT_CASE_1]]({{%.*}} : @trivial $Downgradable):
|
||||
// CHECK-NEXT: [[METATYPE:%.+]] = value_metatype $@thick (Downgradable, Downgradable).Type, {{%.*}} : $(Downgradable, Downgradable)
|
||||
// CHECK-NEXT: // function_ref
|
||||
// CHECK-NEXT: [[DIAGNOSE:%.+]] = function_ref @$Ss27_diagnoseUnexpectedEnumCase
|
||||
// CHECK-NEXT: = apply [[DIAGNOSE]]<(Downgradable, Downgradable)>([[METATYPE]]) : $@convention(thin) <τ_0_0> (@thick τ_0_0.Type) -> Never
|
||||
// CHECK-NEXT: unreachable
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
|
||||
// RUN: %target-swift-frontend -Xllvm -sil-full-demangle -sdk %S/Inputs -I %S/Inputs -enable-source-import %s -emit-silgen -enable-sil-ownership -swift-version 3 -verify | %FileCheck %s
|
||||
|
||||
protocol Foo {}
|
||||
|
||||
// Don't crash mangling single-protocol "composition" types.
|
||||
// CHECK-LABEL: sil hidden @$S15mangling_swift327single_protocol_composition1xyAA3Foo_p_tF
|
||||
func single_protocol_composition(x: protocol<Foo>) {} // expected-warning {{'protocol<...>' composition syntax is deprecated and not needed here}}
|
||||
@@ -1,5 +1,4 @@
|
||||
// RUN: %target-swift-emit-silgen -sdk %S/Inputs %s -I %S/Inputs -enable-source-import -enable-swift3-objc-inference -swift-version 4 -enable-sil-ownership -enable-objc-interop | %FileCheck -check-prefix CHECK-SWIFT4 %s
|
||||
// RUN: %target-swift-emit-silgen -sdk %S/Inputs %s -enable-sil-ownership -I %S/Inputs -enable-source-import -swift-version 3 -enable-objc-interop | %FileCheck -check-prefix CHECK-SWIFT3 %s
|
||||
|
||||
import Foundation
|
||||
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
// RUN: %target-swift-frontend -swift-version 3 -emit-sil -primary-file %s -o /dev/null -verify
|
||||
//
|
||||
// These are tests for diagnostics produced by constant propagation pass.
|
||||
// These tests are specific to swift 3.
|
||||
|
||||
func testArithmeticOverflowSwift3() {
|
||||
// FIXME: Should expect an integer overflow error but none happens now
|
||||
// (see <rdar://problem/39120081>)
|
||||
var _ = Int8(126) + (1 + 1) // expected-warning {{'+' is deprecated: Please use explicit type conversions or Strideable methods for mixed-type arithmetics.}}
|
||||
}
|
||||
@@ -1,38 +0,0 @@
|
||||
// RUN: %target-swift-frontend -enforce-exclusivity=checked -swift-version 3 -emit-sil -primary-file %s -o /dev/null -verify
|
||||
|
||||
import Swift
|
||||
|
||||
// In Swift 3 compatibility mode, diagnostics for exclusive accesses are
|
||||
// warnings not errors.
|
||||
|
||||
func takesTwoInouts<T>(_ p1: inout T, _ p2: inout T) { }
|
||||
|
||||
func simpleInoutDiagnostic() {
|
||||
var i = 7
|
||||
|
||||
// expected-error@+4{{inout arguments are not allowed to alias each other}}
|
||||
// expected-note@+3{{previous aliasing argument}}
|
||||
// expected-warning@+2{{overlapping accesses to 'i', but modification requires exclusive access; consider copying to a local variable}}
|
||||
// expected-note@+1{{conflicting access is here}}
|
||||
takesTwoInouts(&i, &i)
|
||||
}
|
||||
|
||||
struct X {
|
||||
var f = 12
|
||||
}
|
||||
|
||||
func diagnoseOnSameField() {
|
||||
var x = X()
|
||||
|
||||
// expected-warning@+2{{overlapping accesses to 'x.f', but modification requires exclusive access; consider copying to a local variable}}
|
||||
// expected-note@+1{{conflicting access is here}}
|
||||
takesTwoInouts(&x.f, &x.f)
|
||||
}
|
||||
|
||||
func diagnoseSwapOnMutableCollection(_ i: Int, _ j: Int) {
|
||||
var a: [Int] = [1, 2, 3]
|
||||
|
||||
// expected-warning@+2{{overlapping accesses to 'a', but modification requires exclusive access; consider calling MutableCollection.swapAt(_:_:)}}
|
||||
// expected-note@+1{{conflicting access is here}}
|
||||
swap(&a[i], &a[j])
|
||||
}
|
||||
@@ -1,245 +0,0 @@
|
||||
// RUN: %target-typecheck-verify-swift -swift-version 3
|
||||
// RUN: %target-typecheck-verify-swift -swift-version 4
|
||||
|
||||
// These are all legal uses of '!'.
|
||||
struct Fine {
|
||||
var value: Int!
|
||||
|
||||
func m(_ unnamed: Int!, named: Int!) -> Int! { return unnamed }
|
||||
static func s(_ unnamed: Int!, named: Int!) -> Int! { return named }
|
||||
|
||||
init(_ value: Int) { self.value = value }
|
||||
init!() { return nil }
|
||||
|
||||
subscript (
|
||||
index: Int!
|
||||
) -> Int! {
|
||||
return index
|
||||
}
|
||||
|
||||
subscript<T> (
|
||||
index: T!
|
||||
) -> T! {
|
||||
return index
|
||||
}
|
||||
}
|
||||
|
||||
let _: ImplicitlyUnwrappedOptional<Int> = 1 // expected-error {{'ImplicitlyUnwrappedOptional' has been renamed to 'Optional'}}{{8-35=Optional}}
|
||||
let _: ImplicitlyUnwrappedOptional = 1 // expected-error {{'ImplicitlyUnwrappedOptional' has been renamed to 'Optional'}}
|
||||
|
||||
extension ImplicitlyUnwrappedOptional { // expected-error {{'ImplicitlyUnwrappedOptional' has been renamed to 'Optional'}}{{11-38=Optional}}
|
||||
}
|
||||
|
||||
func functionSpelling(
|
||||
_: ImplicitlyUnwrappedOptional<Int> // expected-error {{'ImplicitlyUnwrappedOptional' has been renamed to 'Optional'}}{{6-33=Optional}}
|
||||
) -> ImplicitlyUnwrappedOptional<Int> { // expected-error {{'ImplicitlyUnwrappedOptional' has been renamed to 'Optional'}}{{6-33=Optional}}
|
||||
return 1
|
||||
}
|
||||
|
||||
// Okay, like in the method case.
|
||||
func functionSigil(
|
||||
_: Int!
|
||||
) -> Int! {
|
||||
return 1
|
||||
}
|
||||
|
||||
// Not okay because '!' is not at the top level of the type.
|
||||
func functionSigilArray(
|
||||
_: [Int!] // expected-warning {{using '!' is not allowed here; treating this as '?' instead}}{{10-11=?}}
|
||||
) -> [Int!] { // expected-warning {{using '!' is not allowed here; treating this as '?' instead}}{{10-11=?}}
|
||||
return [1]
|
||||
}
|
||||
|
||||
func genericFunction<T>(
|
||||
iuo: ImplicitlyUnwrappedOptional<T> // expected-error {{'ImplicitlyUnwrappedOptional' has been renamed to 'Optional'}}{{8-35=Optional}}
|
||||
) -> ImplicitlyUnwrappedOptional<T> { // expected-error {{'ImplicitlyUnwrappedOptional' has been renamed to 'Optional'}}{{6-33=Optional}}
|
||||
return iuo
|
||||
}
|
||||
|
||||
// Okay, like in the non-generic case.
|
||||
func genericFunctionSigil<T>(
|
||||
iuo: T!
|
||||
) -> T! {
|
||||
return iuo
|
||||
}
|
||||
|
||||
func genericFunctionSigilArray<T>(
|
||||
// FIXME: We validate these types multiple times resulting in multiple diagnostics
|
||||
iuo: [T!] // expected-warning {{using '!' is not allowed here; treating this as '?' instead}}{{10-11=?}}
|
||||
// expected-warning@-1 {{using '!' is not allowed here; treating this as '?' instead}}{{10-11=?}}
|
||||
// expected-warning@-2 {{using '!' is not allowed here; treating this as '?' instead}}{{10-11=?}}
|
||||
) -> [T!] { // expected-warning {{using '!' is not allowed here; treating this as '?' instead}}{{8-9=?}}
|
||||
// expected-warning@-1 {{using '!' is not allowed here; treating this as '?' instead}}{{8-9=?}}
|
||||
// expected-warning@-2 {{using '!' is not allowed here; treating this as '?' instead}}{{8-9=?}}
|
||||
return iuo
|
||||
}
|
||||
|
||||
protocol P {
|
||||
associatedtype T // expected-note {{protocol requires nested type 'T'; do you want to add it?}}
|
||||
associatedtype U // expected-note {{protocol requires nested type 'U'; do you want to add it?}}
|
||||
}
|
||||
|
||||
struct S : P { // expected-error {{type 'S' does not conform to protocol 'P'}}
|
||||
typealias T = ImplicitlyUnwrappedOptional<Int> // expected-error {{'ImplicitlyUnwrappedOptional' has been renamed to 'Optional'}}{{17-44=Optional}}
|
||||
typealias U = Optional<ImplicitlyUnwrappedOptional<Int>> // expected-error {{'ImplicitlyUnwrappedOptional' has been renamed to 'Optional'}}{{26-53=Optional}}
|
||||
|
||||
typealias V = Int! // expected-warning {{using '!' is not allowed here; treating this as '?' instead}}{{20-21=?}}
|
||||
typealias W = Int!? // expected-warning {{using '!' is not allowed here; treating this as '?' instead}}{{20-21=?}}
|
||||
|
||||
var x: V
|
||||
var y: W
|
||||
var fn1: (Int!) -> Int // expected-warning {{using '!' is not allowed here; treating this as '?' instead}}{{16-17=?}}
|
||||
var fn2: (Int) -> Int! // expected-warning {{using '!' is not allowed here; treating this as '?' instead}}{{24-25=?}}
|
||||
|
||||
subscript (
|
||||
index: ImplicitlyUnwrappedOptional<Int> // expected-error {{'ImplicitlyUnwrappedOptional' has been renamed to 'Optional'}}{{12-39=Optional}}
|
||||
) -> ImplicitlyUnwrappedOptional<Int> { // expected-error {{'ImplicitlyUnwrappedOptional' has been renamed to 'Optional'}}{{12-39=Optional}}
|
||||
return index
|
||||
}
|
||||
|
||||
subscript<T> (
|
||||
index: ImplicitlyUnwrappedOptional<T> // expected-error {{'ImplicitlyUnwrappedOptional' has been renamed to 'Optional'}}{{12-39=Optional}}
|
||||
) -> ImplicitlyUnwrappedOptional<T> { // expected-error {{'ImplicitlyUnwrappedOptional' has been renamed to 'Optional'}}{{12-39=Optional}}
|
||||
return index
|
||||
}
|
||||
}
|
||||
|
||||
func generic<T : P>(_: T) where T.T == ImplicitlyUnwrappedOptional<Int> { } // expected-error {{'ImplicitlyUnwrappedOptional' has been renamed to 'Optional'}}{{40-67=Optional}}
|
||||
func genericOptIUO<T : P>(_: T) where T.U == Optional<ImplicitlyUnwrappedOptional<Int>> {} // expected-error {{'ImplicitlyUnwrappedOptional' has been renamed to 'Optional'}}{{55-82=Optional}}
|
||||
|
||||
func testClosure() -> Int {
|
||||
return {
|
||||
(i: ImplicitlyUnwrappedOptional<Int>) // expected-error {{'ImplicitlyUnwrappedOptional' has been renamed to 'Optional'}}{{9-36=Optional}}
|
||||
-> ImplicitlyUnwrappedOptional<Int> in // expected-error {{'ImplicitlyUnwrappedOptional' has been renamed to 'Optional'}}{{9-36=Optional}}
|
||||
return i
|
||||
}(1)!
|
||||
}
|
||||
|
||||
_ = Array<Int!>() // expected-warning {{using '!' is not allowed here; treating this as '?' instead}}{{14-15=?}}
|
||||
let _: Array<Int!> = [1] // expected-warning {{using '!' is not allowed here; treating this as '?' instead}}{{17-18=?}}
|
||||
_ = [Int!]() // expected-warning {{using '!' is not allowed here; treating this as '?' instead}}{{9-10=?}}
|
||||
let _: [Int!] = [1] // expected-warning {{using '!' is not allowed here; treating this as '?' instead}}{{12-13=?}}
|
||||
_ = Optional<Int!>(nil) // expected-warning {{using '!' is not allowed here; treating this as '?' instead}}{{17-18=?}}
|
||||
let _: Optional<Int!> = nil // expected-warning {{using '!' is not allowed here; treating this as '?' instead}}{{20-21=?}}
|
||||
_ = Int!?(0) // expected-warning {{using '!' is not allowed here; treating this as '?' instead}}{{8-9=?}}
|
||||
let _: Int!? = 0 // expected-warning {{using '!' is not allowed here; treating this as '?' instead}}{{11-12=?}}
|
||||
_ = (
|
||||
Int!, // expected-warning {{using '!' is not allowed here; treating this as '?' instead}}{{6-7=?}}
|
||||
Float!, // expected-warning {{using '!' is not allowed here; treating this as '?' instead}}{{8-9=?}}
|
||||
String! // expected-warning {{using '!' is not allowed here; treating this as '?' instead}}{{9-10=?}}
|
||||
)(1, 2.0, "3")
|
||||
let _: (
|
||||
Int!, // expected-warning {{using '!' is not allowed here; treating this as '?' instead}}{{6-7=?}}
|
||||
Float!, // expected-warning {{using '!' is not allowed here; treating this as '?' instead}}{{8-9=?}}
|
||||
String! // expected-warning {{using '!' is not allowed here; treating this as '?' instead}}{{9-10=?}}
|
||||
) = (1, 2.0, "3")
|
||||
|
||||
struct Generic<T, U, C> {
|
||||
init(_ t: T, _ u: U, _ c: C) {}
|
||||
}
|
||||
_ = Generic<Int!, // expected-warning {{using '!' is not allowed here; treating this as '?' instead}}{{16-17=?}}
|
||||
Float!, // expected-warning {{using '!' is not allowed here; treating this as '?' instead}}{{18-19=?}}
|
||||
String!>(1, 2.0, "3") // expected-warning {{using '!' is not allowed here; treating this as '?' instead}}{{19-20=?}}
|
||||
let _: Generic<Int!, // expected-warning {{using '!' is not allowed here; treating this as '?' instead}}{{19-20=?}}
|
||||
Float!, // expected-warning {{using '!' is not allowed here; treating this as '?' instead}}{{21-22=?}}
|
||||
String!> = Generic(1, 2.0, "3") // expected-warning {{using '!' is not allowed here; treating this as '?' instead}}{{22-23=?}}
|
||||
|
||||
func vararg(_ first: Int, more: Int!...) { // expected-warning {{using '!' is not allowed here; treating this as '?' instead}}{{36-37=?}}
|
||||
}
|
||||
|
||||
func varargIdentifier(_ first: Int, more: ImplicitlyUnwrappedOptional<Int>...) { // expected-error {{'ImplicitlyUnwrappedOptional' has been renamed to 'Optional'}}{{43-70=Optional}}
|
||||
}
|
||||
|
||||
func iuoInTuple() -> (Int!) { // expected-warning {{using '!' is not allowed here; treating this as '?' instead}}{{26-27=?}}
|
||||
return 1
|
||||
}
|
||||
|
||||
func iuoInTupleIdentifier() -> (ImplicitlyUnwrappedOptional<Int>) { // expected-error {{'ImplicitlyUnwrappedOptional' has been renamed to 'Optional'}}{{33-60=Optional}}
|
||||
return 1
|
||||
}
|
||||
|
||||
func iuoInTuple2() -> (Float, Int!) { // expected-warning {{using '!' is not allowed here; treating this as '?' instead}}{{34-35=?}}
|
||||
return (1.0, 1)
|
||||
}
|
||||
|
||||
func iuoInTuple2Identifier() -> (Float, ImplicitlyUnwrappedOptional<Int>) { // expected-error {{'ImplicitlyUnwrappedOptional' has been renamed to 'Optional'}}{{41-68=Optional}}
|
||||
return (1.0, 1)
|
||||
}
|
||||
|
||||
func takesFunc(_ fn: (Int!) -> Int) -> Int { // expected-warning {{using '!' is not allowed here; treating this as '?' instead}}{{26-27=?}}
|
||||
return fn(0)
|
||||
}
|
||||
|
||||
func takesFuncIdentifier(_ fn: (ImplicitlyUnwrappedOptional<Int>) -> Int) -> Int { // expected-error {{'ImplicitlyUnwrappedOptional' has been renamed to 'Optional'}}{{33-60=Optional}}
|
||||
return fn(0)
|
||||
}
|
||||
|
||||
func takesFunc2(_ fn: (Int) -> Int!) -> Int { // expected-warning {{using '!' is not allowed here; treating this as '?' instead}}{{35-36=?}}
|
||||
return fn(0)!
|
||||
}
|
||||
|
||||
func takesFunc2Identifier(_ fn: (Int) -> ImplicitlyUnwrappedOptional<Int>) -> Int { // expected-error {{'ImplicitlyUnwrappedOptional' has been renamed to 'Optional'}}{{42-69=Optional}}
|
||||
return fn(0)!
|
||||
}
|
||||
|
||||
func returnsFunc() -> (Int!) -> Int { // expected-warning {{using '!' is not allowed here; treating this as '?' instead}}{{27-28=?}}
|
||||
return { $0! }
|
||||
}
|
||||
|
||||
func returnsFuncIdentifier() -> (ImplicitlyUnwrappedOptional<Int>) -> Int { // expected-error {{'ImplicitlyUnwrappedOptional' has been renamed to 'Optional'}}{{34-61=Optional}}
|
||||
return { $0! }
|
||||
}
|
||||
|
||||
func returnsFunc2() -> (Int) -> Int! { // expected-warning {{using '!' is not allowed here; treating this as '?' instead}}{{36-37=?}}
|
||||
return { $0 }
|
||||
}
|
||||
|
||||
func returnsFunc2Identifier() -> (Int) -> ImplicitlyUnwrappedOptional<Int> { // expected-error {{'ImplicitlyUnwrappedOptional' has been renamed to 'Optional'}}{{43-70=Optional}}
|
||||
return { $0 }
|
||||
}
|
||||
|
||||
let x0 = 1 as ImplicitlyUnwrappedOptional // expected-error {{'ImplicitlyUnwrappedOptional' has been renamed to 'Optional'}}{{15-42=Optional}}
|
||||
|
||||
let x: Int? = 1
|
||||
let y0: Int = x as Int! // expected-warning {{using '!' here is deprecated and will be removed in a future release}}
|
||||
let y1: Int = (x as Int!)! // expected-warning {{using '!' here is deprecated and will be removed in a future release}}
|
||||
let z0: Int = x as! Int! // expected-warning {{using '!' here is deprecated and will be removed in a future release}}
|
||||
// expected-warning@-1 {{forced cast from 'Int?' to 'Int' only unwraps optionals; did you mean to use '!'?}}
|
||||
let z1: Int = (x as! Int!)! // expected-warning {{using '!' here is deprecated and will be removed in a future release}}
|
||||
// expected-warning@-1 {{forced cast of 'Int?' to same type has no effect}}
|
||||
let w0: Int = (x as? Int!)! // expected-warning {{using '!' here is deprecated and will be removed in a future release}}
|
||||
// expected-warning@-1 {{conditional cast from 'Int?' to 'Int?' always succeeds}}
|
||||
let w1: Int = (x as? Int!)!! // expected-warning {{using '!' here is deprecated and will be removed in a future release}}
|
||||
// expected-warning@-1 {{conditional cast from 'Int?' to 'Int?' always succeeds}}
|
||||
|
||||
func overloadedByOptionality(_ a: inout Int!) {}
|
||||
// expected-note@-1 {{'overloadedByOptionality' previously declared here}}
|
||||
func overloadedByOptionality(_ a: inout Int?) {}
|
||||
// expected-error@-1 {{invalid redeclaration of 'overloadedByOptionality'}}
|
||||
|
||||
func takesInOutIUO(_ i: inout Int!) {}
|
||||
func takesInOutOpt(_ o: inout Int?) {}
|
||||
|
||||
func testInOutOptionality() {
|
||||
var i: Int! = 1
|
||||
var o: Int? = 2
|
||||
|
||||
takesInOutIUO(&i)
|
||||
takesInOutOpt(&i)
|
||||
takesInOutIUO(&o)
|
||||
takesInOutOpt(&o)
|
||||
|
||||
overloadedByOptionality(&i)
|
||||
overloadedByOptionality(&o)
|
||||
}
|
||||
|
||||
struct T {
|
||||
let i: Int!
|
||||
var j: Int!
|
||||
let k: Int
|
||||
}
|
||||
|
||||
func select(i: Int!, m: Int, t: T) {
|
||||
let _ = i ? i : m // expected-error {{result values in '? :' expression have mismatching types 'Int?' and 'Int'}}
|
||||
let _ = t.i ? t.j : t.k // expected-error {{result values in '? :' expression have mismatching types 'Int?' and 'Int'}}
|
||||
}
|
||||
@@ -1,87 +0,0 @@
|
||||
// RUN: %target-swift-frontend -typecheck -verify -swift-version 3 %s
|
||||
|
||||
let s = "Hello"
|
||||
let ss = s[s.startIndex..<s.endIndex]
|
||||
|
||||
// CTP_Initialization
|
||||
do {
|
||||
let s1: String = { return ss }()
|
||||
_ = s1
|
||||
}
|
||||
|
||||
// CTP_ReturnStmt
|
||||
do {
|
||||
func returnsAString() -> String {
|
||||
return ss
|
||||
}
|
||||
}
|
||||
|
||||
// CTP_ThrowStmt
|
||||
// Doesn't really make sense for this fix-it - see case in diagnoseContextualConversionError:
|
||||
// The conversion destination of throw is always ErrorType (at the moment)
|
||||
// if this ever expands, this should be a specific form like () is for
|
||||
// return.
|
||||
|
||||
// CTP_EnumCaseRawValue
|
||||
// Substrings can't be raw values because they aren't literals.
|
||||
|
||||
// CTP_DefaultParameter
|
||||
do {
|
||||
func foo(x: String = ss) {}
|
||||
}
|
||||
|
||||
// CTP_CalleeResult
|
||||
do {
|
||||
func getSubstring() -> Substring { return ss } // expected-error {{cannot convert return expression of type 'String' to return type 'Substring'}}
|
||||
let gottenString : String = getSubstring() // expected-error {{cannot convert value of type 'Substring' to specified type 'String'}} {{31-31=String(}} {{45-45=)}}
|
||||
_ = gottenString
|
||||
}
|
||||
|
||||
// CTP_CallArgument
|
||||
do {
|
||||
func takesAString(_ s: String) {}
|
||||
takesAString(ss)
|
||||
}
|
||||
|
||||
// CTP_ClosureResult
|
||||
do {
|
||||
[ss].map { (x: Substring) -> String in x } // expected-error {{'Substring' is not convertible to 'String'}}
|
||||
}
|
||||
|
||||
// CTP_ArrayElement
|
||||
do {
|
||||
let a: [String] = [ ss ]
|
||||
_ = a
|
||||
}
|
||||
|
||||
// CTP_DictionaryKey
|
||||
do {
|
||||
let d: [ String : String ] = [ ss : s ]
|
||||
_ = d
|
||||
}
|
||||
|
||||
// CTP_DictionaryValue
|
||||
do {
|
||||
let d: [ String : String ] = [ s : ss ]
|
||||
_ = d
|
||||
}
|
||||
|
||||
// CTP_CoerceOperand
|
||||
do {
|
||||
let s1: String = ss as String
|
||||
_ = s1
|
||||
}
|
||||
|
||||
// CTP_AssignSource
|
||||
do {
|
||||
let s1: String = ss
|
||||
_ = s1
|
||||
}
|
||||
|
||||
func takesString(_ s: String) {}
|
||||
|
||||
func apply(_ fn: (String) -> (), _ s: String) {
|
||||
fn(s[s.startIndex..<s.endIndex])
|
||||
let _: String = s[s.startIndex..<s.endIndex]
|
||||
_ = s[s.startIndex..<s.endIndex] as String
|
||||
}
|
||||
@@ -1,43 +0,0 @@
|
||||
// RUN: %target-typecheck-verify-swift -swift-version 3
|
||||
// All of these cases should work in Swift 4, so do a normal without -verify should succeed:
|
||||
// RUN: %target-swift-frontend -typecheck %s -swift-version 4
|
||||
|
||||
struct Struct {}
|
||||
|
||||
extension Struct: Equatable {}
|
||||
// expected-error@-1{{implementation of 'Equatable' cannot be automatically synthesized in an extension in Swift 3}}
|
||||
extension Struct: Codable {}
|
||||
// expected-error@-1{{implementation of 'Encodable' cannot be automatically synthesized in an extension in Swift 3}}
|
||||
// expected-error@-2{{implementation of 'Decodable' cannot be automatically synthesized in an extension in Swift 3}}
|
||||
|
||||
final class Final {}
|
||||
extension Final: Codable {}
|
||||
// expected-error@-1{{implementation of 'Encodable' cannot be automatically synthesized in an extension in Swift 3}}
|
||||
// expected-error@-2{{implementation of 'Decodable' cannot be automatically synthesized in an extension in Swift 3}}
|
||||
|
||||
class Nonfinal {}
|
||||
extension Nonfinal: Encodable {}
|
||||
// expected-error@-1{{implementation of 'Encodable' cannot be automatically synthesized in an extension in Swift 3}}
|
||||
|
||||
|
||||
enum NoValues {
|
||||
case a, b
|
||||
}
|
||||
|
||||
// This case has been able to be synthesized since at least Swift 3, so it
|
||||
// should work in that mode.
|
||||
extension NoValues: Equatable {}
|
||||
extension NoValues: Hashable {}
|
||||
|
||||
extension NoValues: CaseIterable {}
|
||||
// expected-error@-1{{implementation of 'CaseIterable' cannot be automatically synthesized in an extension in Swift 3}}
|
||||
// expected-error@-2{{type 'NoValues' does not conform to protocol 'CaseIterable'}}
|
||||
|
||||
enum Values {
|
||||
case a(Int), b
|
||||
}
|
||||
|
||||
extension Values: Equatable {}
|
||||
// expected-error@-1{{implementation of 'Equatable' cannot be automatically synthesized in an extension in Swift 3}}
|
||||
extension Values: Hashable {}
|
||||
// expected-error@-1{{implementation of 'Hashable' cannot be automatically synthesized in an extension in Swift 3}}
|
||||
@@ -1,10 +1,6 @@
|
||||
// RUN: %target-swift-frontend -emit-ir -o/dev/null -parse-as-library -module-name test -validate-tbd-against-ir=all -swift-version 3 %s
|
||||
// RUN: %target-swift-frontend -emit-ir -o/dev/null -parse-as-library -module-name test -validate-tbd-against-ir=all -swift-version 4 %s
|
||||
// RUN: %target-swift-frontend -emit-ir -o/dev/null -parse-as-library -module-name test -validate-tbd-against-ir=all -swift-version 3 %s -enable-testing
|
||||
// RUN: %target-swift-frontend -emit-ir -o/dev/null -parse-as-library -module-name test -validate-tbd-against-ir=all -swift-version 4 %s -enable-testing
|
||||
// RUN: %target-swift-frontend -emit-ir -o/dev/null -parse-as-library -module-name test -validate-tbd-against-ir=all -swift-version 3 %s -O
|
||||
// RUN: %target-swift-frontend -emit-ir -o/dev/null -parse-as-library -module-name test -validate-tbd-against-ir=all -swift-version 4 %s -O
|
||||
// RUN: %target-swift-frontend -emit-ir -o/dev/null -parse-as-library -module-name test -validate-tbd-against-ir=all -swift-version 3 %s -enable-testing -O
|
||||
// RUN: %target-swift-frontend -emit-ir -o/dev/null -parse-as-library -module-name test -validate-tbd-against-ir=all -swift-version 4 %s -enable-testing -O
|
||||
|
||||
public func publicNoArgs() {}
|
||||
|
||||
@@ -1,81 +0,0 @@
|
||||
// RUN: %target-typecheck-verify-swift -swift-version 3 %s
|
||||
|
||||
@available(swift 3)
|
||||
func swiftShortThree() {}
|
||||
|
||||
@available(swift 3.0)
|
||||
func swiftShortThreePointOh() {}
|
||||
|
||||
@available(swift, introduced: 3.0)
|
||||
func swiftThreePointOh() {}
|
||||
|
||||
@available(swift, introduced: 3.0, obsoleted: 4.0)
|
||||
func swiftThreePointOhOnly() {}
|
||||
|
||||
@available(swift, deprecated: 3.0)
|
||||
func swiftDeprecatedThreePointOh() {}
|
||||
|
||||
@available(swift, obsoleted: 3.0)
|
||||
func swiftObsoletedThreePointOh() {} // expected-note {{was obsoleted in Swift 3.0}}
|
||||
|
||||
@available(swift, introduced: 3, obsoleted: 4.0)
|
||||
class SwiftThreeOnly {}
|
||||
|
||||
@available(swift 4)
|
||||
func swiftShortFour() {} // expected-note {{was introduced in Swift 4}}
|
||||
|
||||
@available(swift 4.0)
|
||||
func swiftShortFourPointOh() {} // expected-note {{was introduced in Swift 4.0}}
|
||||
|
||||
@available(swift, introduced: 4)
|
||||
func swiftFour() {} // expected-note {{was introduced in Swift 4}}
|
||||
|
||||
@available(swift, introduced: 4.0)
|
||||
func swiftFourPointOh() {} // expected-note {{was introduced in Swift 4.0}}
|
||||
|
||||
@available(swift, introduced: 4.0, message: "uses abc")
|
||||
func swiftFourPointOhWithMessage() {} // expected-note {{was introduced in Swift 4.0}}
|
||||
|
||||
@available(swift 4)
|
||||
class SwiftShortFour {} // expected-note {{was introduced in Swift 4}}
|
||||
|
||||
@available(swift, introduced: 4, message: "uses pqr")
|
||||
class SwiftFourWithMessage {} // expected-note {{was introduced in Swift 4}}
|
||||
|
||||
|
||||
swiftShortThree()
|
||||
swiftShortThreePointOh()
|
||||
swiftThreePointOh()
|
||||
swiftThreePointOhOnly()
|
||||
swiftDeprecatedThreePointOh() // expected-warning {{is deprecated}}
|
||||
swiftObsoletedThreePointOh() // expected-error {{is unavailable}}
|
||||
let a : SwiftThreeOnly
|
||||
|
||||
|
||||
swiftShortFour() // expected-error {{is unavailable}}
|
||||
swiftShortFourPointOh() // expected-error {{is unavailable}}
|
||||
swiftFour() // expected-error {{is unavailable}}
|
||||
swiftFourPointOh() // expected-error {{is unavailable}}
|
||||
swiftFourPointOhWithMessage() // expected-error {{is unavailable: uses abc}}
|
||||
let aa : SwiftShortFour // expected-error {{is unavailable}}
|
||||
let bb : SwiftFourWithMessage // expected-error {{is unavailable: uses pqr}}
|
||||
|
||||
@available(*, deprecated, message: "found the top-level decl")
|
||||
func shadowedByMember3() {}
|
||||
@available(*, deprecated, message: "found the top-level decl")
|
||||
func shadowedByMember4() {}
|
||||
|
||||
struct Wrapper {
|
||||
@available(swift, introduced: 3.0, obsoleted: 4.0)
|
||||
@available(*, deprecated, message: "found the member decl")
|
||||
func shadowedByMember3() {}
|
||||
|
||||
@available(swift, introduced: 4.0)
|
||||
@available(*, deprecated, message: "found the member decl")
|
||||
func shadowedByMember4() {}
|
||||
|
||||
func test() {
|
||||
shadowedByMember3() // expected-warning {{found the member decl}}
|
||||
shadowedByMember4() // expected-warning {{found the top-level decl}}
|
||||
}
|
||||
}
|
||||
@@ -1,145 +0,0 @@
|
||||
// RUN: %target-typecheck-verify-swift -swift-version 3
|
||||
|
||||
enum Runcible {
|
||||
case spoon
|
||||
case hat
|
||||
@_downgrade_exhaustivity_check
|
||||
case fork
|
||||
}
|
||||
|
||||
enum Trioptional {
|
||||
case some(Runcible)
|
||||
case just(Runcible)
|
||||
case none
|
||||
}
|
||||
|
||||
enum Fungible {
|
||||
case cash
|
||||
case giftCard
|
||||
}
|
||||
|
||||
func missingCases(x: Runcible?, y: Runcible?, z: Trioptional) {
|
||||
// Should warn in S3 mode that `fork` isn't used
|
||||
switch x! { // expected-warning {{switch must be exhaustive}}
|
||||
// expected-note@-1 {{add missing case: '.fork'}}
|
||||
case .spoon:
|
||||
break
|
||||
case .hat:
|
||||
break
|
||||
}
|
||||
|
||||
// Should warn in S3 mode that `fork` isn't used
|
||||
switch (x!, y!) { // expected-warning {{switch must be exhaustive}}
|
||||
// expected-note@-1 2 {{add missing case:}}
|
||||
case (.spoon, .spoon):
|
||||
break
|
||||
case (.spoon, .hat):
|
||||
break
|
||||
case (.hat, .spoon):
|
||||
break
|
||||
case (.hat, .hat):
|
||||
break
|
||||
}
|
||||
|
||||
// Should error, since `fork` is used but not totally covered
|
||||
switch (x!, y!) { // expected-error {{switch must be exhaustive}}
|
||||
// expected-note@-1 {{add missing case: '(.fork, .hat)'}}
|
||||
// expected-note@-2 {{add missing case: '(_, .fork)'}}
|
||||
case (.spoon, .spoon):
|
||||
break
|
||||
case (.spoon, .hat):
|
||||
break
|
||||
case (.hat, .spoon):
|
||||
break
|
||||
case (.hat, .hat):
|
||||
break
|
||||
case (.fork, .spoon):
|
||||
break
|
||||
}
|
||||
|
||||
// Should error, since `fork` is used but not totally covered
|
||||
switch (x!, y!) { // expected-error {{switch must be exhaustive}}
|
||||
// expected-note@-1 {{add missing case: '(.fork, _)'}}
|
||||
// expected-note@-2 {{add missing case: '(.spoon, .fork)'}}
|
||||
case (.spoon, .spoon):
|
||||
break
|
||||
case (.spoon, .hat):
|
||||
break
|
||||
case (.hat, .spoon):
|
||||
break
|
||||
case (.hat, .hat):
|
||||
break
|
||||
case (.hat, .fork):
|
||||
break
|
||||
}
|
||||
|
||||
// Should warn in S3 mode that `fork` isn't used
|
||||
switch x { // expected-warning {{switch must be exhaustive}}
|
||||
// expected-note@-1 {{add missing case: '.some(.fork)'}}
|
||||
case .some(.spoon):
|
||||
break
|
||||
case .some(.hat):
|
||||
break
|
||||
case .none:
|
||||
break
|
||||
}
|
||||
|
||||
// Should warn in S3 mode that `fork` isn't used
|
||||
switch (x, y!) { // expected-warning {{switch must be exhaustive}}
|
||||
// expected-note@-1 {{add missing case: '(.some(.fork), _)'}}
|
||||
// expected-note@-2 {{add missing case: '(_, .fork)'}}
|
||||
case (.some(.spoon), .spoon):
|
||||
break
|
||||
case (.some(.spoon), .hat):
|
||||
break
|
||||
case (.some(.hat), .spoon):
|
||||
break
|
||||
case (.some(.hat), .hat):
|
||||
break
|
||||
case (.none, .spoon):
|
||||
break
|
||||
case (.none, .hat):
|
||||
break
|
||||
}
|
||||
|
||||
// Should warn in S3 mode that `fork` isn't used
|
||||
switch (x, y) { // expected-error {{switch must be exhaustive}}
|
||||
// expected-note@-1 {{add missing case: '(.some(.fork), _)'}}
|
||||
// expected-note@-2 {{add missing case: '(_, .some(.fork))'}}
|
||||
// expected-note@-3 {{add missing case: '(.none, _)'}}
|
||||
case (.some(.spoon), .some(.spoon)):
|
||||
break
|
||||
case (.some(.spoon), .some(.hat)):
|
||||
break
|
||||
case (.some(.spoon), .none):
|
||||
break
|
||||
case (.some(.hat), .some(.spoon)):
|
||||
break
|
||||
case (.some(.hat), .some(.hat)):
|
||||
break
|
||||
case (.some(.hat), .none):
|
||||
break
|
||||
case (.some(.hat), .some(.spoon)): // expected-warning {{case is already handled by previous patterns; consider removing it}}
|
||||
break
|
||||
case (.some(.hat), .some(.hat)): // expected-warning {{case is already handled by previous patterns; consider removing it}}
|
||||
break
|
||||
case (.some(.hat), .none): // expected-warning {{case is already handled by previous patterns; consider removing it}}
|
||||
break
|
||||
}
|
||||
|
||||
// Should warn in S3 mode that `fork` isn't used
|
||||
switch z { // expected-warning {{switch must be exhaustive}}
|
||||
// expected-note@-1 {{add missing case: '.some(.fork)'}}
|
||||
// expected-note@-2 {{add missing case: '.just(.fork)'}}
|
||||
case .some(.spoon):
|
||||
break
|
||||
case .some(.hat):
|
||||
break
|
||||
case .just(.spoon):
|
||||
break
|
||||
case .just(.hat):
|
||||
break
|
||||
case .none:
|
||||
break
|
||||
}
|
||||
}
|
||||
@@ -1,43 +0,0 @@
|
||||
// RUN: %target-swift-frontend -disable-objc-attr-requires-foundation-module -typecheck -verify %s -swift-version 3 -warn-swift3-objc-inference-complete
|
||||
// REQUIRES: objc_interop
|
||||
|
||||
import Foundation
|
||||
|
||||
class ObjCSubclass : NSObject {
|
||||
func foo() { } // expected-warning{{inference of '@objc' for members of Objective-C-derived classes is deprecated}}
|
||||
// expected-note@-1{{add '@objc' to continue exposing an Objective-C entry point (Swift 3 behavior)}}{{3-3=@objc }}
|
||||
// expected-note@-2{{add '@nonobjc' to suppress the Objective-C entry point (Swift 4 behavior)}}{{3-3=@nonobjc }}
|
||||
|
||||
var bar: NSObject? = nil // expected-warning{{inference of '@objc' for members of Objective-C-derived classes is deprecated}}
|
||||
// expected-note@-1{{add '@objc' to continue exposing an Objective-C entry point (Swift 3 behavior)}}{{3-3=@objc }}
|
||||
// expected-note@-2{{add '@nonobjc' to suppress the Objective-C entry point (Swift 4 behavior)}}{{3-3=@nonobjc }}
|
||||
}
|
||||
|
||||
class DynamicMembers {
|
||||
dynamic func foo() { } // expected-warning{{inference of '@objc' for 'dynamic' members is deprecated}}{{3-3=@objc }}
|
||||
|
||||
dynamic var bar: NSObject? = nil // expected-warning{{inference of '@objc' for 'dynamic' members is deprecated}}{{3-3=@objc }}
|
||||
}
|
||||
|
||||
class GenericClass<T>: NSObject {}
|
||||
|
||||
class SubclassOfGeneric: GenericClass<Int> {
|
||||
func foo() { } // expected-warning{{inference of '@objc' for members of Objective-C-derived classes is deprecated}}
|
||||
// expected-note@-1{{add '@objc' to continue exposing an Objective-C entry point (Swift 3 behavior)}}{{3-3=@objc }}
|
||||
// expected-note@-2{{add '@nonobjc' to suppress the Objective-C entry point (Swift 4 behavior)}}{{3-3=@nonobjc }}
|
||||
}
|
||||
|
||||
@objc(SubclassOfGenericCustom)
|
||||
class SubclassOfGenericCustomName: GenericClass<Int> {
|
||||
func foo() { } // expected-warning{{inference of '@objc' for members of Objective-C-derived classes is deprecated}}
|
||||
// expected-note@-1{{add '@objc' to continue exposing an Objective-C entry point (Swift 3 behavior)}}{{3-3=@objc }}
|
||||
// expected-note@-2{{add '@nonobjc' to suppress the Objective-C entry point (Swift 4 behavior)}}{{3-3=@nonobjc }}
|
||||
}
|
||||
|
||||
// Suppress diagnostices about references to inferred @objc declarations
|
||||
// in this mode.
|
||||
func test(sc: ObjCSubclass, dm: DynamicMembers) {
|
||||
_ = #selector(sc.foo)
|
||||
_ = #selector(getter: dm.bar)
|
||||
_ = #keyPath(DynamicMembers.bar)
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
// RUN: %target-swift-frontend -disable-objc-attr-requires-foundation-module -typecheck -verify %s -swift-version 3
|
||||
// REQUIRES: objc_interop
|
||||
|
||||
import Foundation
|
||||
|
||||
class C : NSObject { }
|
||||
|
||||
extension C {
|
||||
func foo() { }
|
||||
}
|
||||
|
||||
class D : C { }
|
||||
|
||||
extension D {
|
||||
override func foo() { } // do not warn
|
||||
}
|
||||
@@ -1,104 +0,0 @@
|
||||
// RUN: %target-swift-frontend -disable-objc-attr-requires-foundation-module -typecheck -verify %s -swift-version 3 -warn-swift3-objc-inference-minimal
|
||||
// REQUIRES: objc_interop
|
||||
|
||||
import Foundation
|
||||
|
||||
struct SwiftStruct { }
|
||||
|
||||
class ObjCSubclass : NSObject {
|
||||
func foo() { } // expected-note 2{{add '@objc' to expose this instance method to Objective-C}}{{3-3=@objc }}
|
||||
var bar: NSObject? = nil // expected-note 2{{add '@objc' to expose this var to Objective-C}}{{3-3=@objc }}
|
||||
|
||||
var isEditing: Bool { // expected-warning{{var 'isEditing' with '@objc' setter depends on deprecated inference of '@objc'}}{{3-3=@objc }}
|
||||
get { return false }
|
||||
|
||||
@objc(setEditing:)
|
||||
set { }
|
||||
}
|
||||
|
||||
subscript (i: Int) -> NSObject? { // expected-warning{{'subscript' with '@objc' getter depends on deprecated inference of '@objc'}}{{3-3=@objc }}
|
||||
@objc(objectAtIndex:)
|
||||
get {
|
||||
return nil
|
||||
}
|
||||
|
||||
set { }
|
||||
}
|
||||
|
||||
@IBInspectable var ibvar: SwiftStruct = SwiftStruct() // expected-warning{{'@IBInspectable' attribute is meaningless on a property that cannot be represented in Objective-C}}{{3-18=}}
|
||||
@GKInspectable var gkvar: SwiftStruct = SwiftStruct() // expected-warning{{'@GKInspectable' attribute is meaningless on a property that cannot be represented in Objective-C}}{{3-18=}}
|
||||
}
|
||||
|
||||
class DynamicMembers {
|
||||
dynamic func foo() { } // expected-warning{{inference of '@objc' for 'dynamic' members is deprecated}}{{3-3=@objc }}
|
||||
|
||||
dynamic var bar: NSObject? = nil // expected-warning{{inference of '@objc' for 'dynamic' members is deprecated}}{{3-3=@objc }}
|
||||
|
||||
func overridableFunc() { }
|
||||
var overridableVar: NSObject? = nil
|
||||
}
|
||||
|
||||
extension ObjCSubclass {
|
||||
func overridableFunc() { } // expected-note{{add '@objc' to expose this instance method to Objective-C}}{{3-3=@objc }}
|
||||
|
||||
var overridableVar: NSObject? { // expected-note{{add '@objc' to expose this var to Objective-C}}{{3-3=@objc }}
|
||||
get { return nil }
|
||||
set { }
|
||||
}
|
||||
}
|
||||
|
||||
class ObjCSubSubclass : ObjCSubclass {
|
||||
override func foo() { } // okay: from the class
|
||||
|
||||
override var bar: NSObject? { // okay: from the class
|
||||
get { return nil }
|
||||
set { }
|
||||
}
|
||||
|
||||
override func overridableFunc() { } // expected-warning{{override of instance method 'overridableFunc()' from extension of 'ObjCSubclass' depends on deprecated inference of '@objc'}}
|
||||
|
||||
override var overridableVar: NSObject? { // expected-warning{{override of var 'overridableVar' from extension of 'ObjCSubclass' depends on deprecated inference of '@objc'}}
|
||||
get { return nil }
|
||||
set { }
|
||||
}
|
||||
}
|
||||
|
||||
class SubclassDynamicMembers : DynamicMembers {
|
||||
override func overridableFunc() { } // okay, explicit dynamic
|
||||
|
||||
override var overridableVar: NSObject? { // okay, explicit dynamic
|
||||
get { return nil }
|
||||
set { }
|
||||
}
|
||||
}
|
||||
|
||||
func testSelector(sc: ObjCSubclass, dm: DynamicMembers) {
|
||||
_ = #selector(sc.foo) // expected-warning{{argument of '#selector' refers to instance method 'foo()' in 'ObjCSubclass' that depends on '@objc' inference deprecated in Swift 4}}
|
||||
_ = #selector(getter: dm.bar) // okay, explicit dynamic
|
||||
}
|
||||
|
||||
func testKeypath(dm: DynamicMembers) {
|
||||
_ = #keyPath(ObjCSubclass.bar) // expected-warning{{argument of '#keyPath' refers to property 'bar' in 'ObjCSubclass' that depends on '@objc' inference deprecated in Swift 4}}
|
||||
_ = #keyPath(DynamicMembers.bar) // okay: dynamic keyword implies @objc
|
||||
}
|
||||
|
||||
func testDynamicCalls(ao: AnyObject) {
|
||||
ao.foo?() // expected-warning{{reference to instance method 'foo()' of 'ObjCSubclass' depends on '@objc' inference deprecated in Swift 4}}
|
||||
_ = ao.bar! // expected-warning{{reference to var 'bar' of 'ObjCSubclass' depends on '@objc' inference deprecated in Swift 4}}
|
||||
}
|
||||
|
||||
// Subclass uses superclass members to satisfy an @objc protocol requirement.
|
||||
// rdar://problem/32431838
|
||||
@objc public protocol P {
|
||||
func method()
|
||||
@objc optional func optionalMethod()
|
||||
}
|
||||
|
||||
class C : NSObject {
|
||||
func method() { } // expected-note{{add '@objc' to expose this instance method to Objective-C}}{{3-3=@objc }}
|
||||
func optionalMethod() { } // expected-note{{add '@objc' to expose this instance method to Objective-C}}{{3-3=@objc }}
|
||||
}
|
||||
|
||||
class S : C, P {}
|
||||
// expected-warning@-1{{use of instance method 'method()' to satisfy a requirement of protocol 'P' depends on '@objc' inference deprecated in Swift 4}}
|
||||
// expected-warning@-2{{use of instance method 'optionalMethod()' to satisfy a requirement of protocol 'P' depends on '@objc' inference deprecated in Swift 4}}
|
||||
@@ -1,4 +1,3 @@
|
||||
// RUN: %target-typecheck-verify-swift -swift-version 3
|
||||
// RUN: %target-typecheck-verify-swift -swift-version 4
|
||||
|
||||
open class AnOpenClass {
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
// RUN: %target-typecheck-verify-swift -swift-version 3
|
||||
// RUN: %target-typecheck-verify-swift -swift-version 4
|
||||
|
||||
class C { }
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
// RUN: %target-typecheck-verify-swift -swift-version 3
|
||||
|
||||
func foo(fn: (() -> ()) -> ()) {
|
||||
fn { fn {} } // expected-warning {{passing a closure which captures a non-escaping function parameter 'fn' to a call to a non-escaping function parameter can allow re-entrant modification of a variable and will be illegal in Swift 4}}
|
||||
}
|
||||
@@ -1,7 +1,4 @@
|
||||
// Try with and without whole module optimization, Swift 3 and Swift 4 mode
|
||||
|
||||
// RUN: %target-build-swift -swift-version 3 %S/Inputs/library.swift %S/main.swift
|
||||
// RUN: %target-build-swift -swift-version 3 -whole-module-optimization %S/Inputs/library.swift %S/main.swift
|
||||
// Try with and without whole module optimization
|
||||
|
||||
// RUN: %target-build-swift -swift-version 4 %S/Inputs/library.swift %S/main.swift
|
||||
// RUN: %target-build-swift -swift-version 4 -whole-module-optimization %S/Inputs/library.swift %S/main.swift
|
||||
|
||||
@@ -1,12 +1,5 @@
|
||||
// RUN: %empty-directory(%t)
|
||||
|
||||
// RUN: mkdir -p %t/onone %t/wmo
|
||||
// RUN: %target-build-swift -emit-module -emit-module-path %t/onone/library.swiftmodule -module-name=library -emit-library %S/Inputs/library1.swift %S/Inputs/library2.swift -o %t/onone/library.%target-dylib-extension -swift-version 3
|
||||
// RUN: %target-build-swift %S/main.swift %t/onone/library.%target-dylib-extension -I %t/onone/ -o %t/onone/main -swift-version 3
|
||||
|
||||
// RUN: %target-build-swift -emit-module -emit-module-path %t/wmo/library.swiftmodule -module-name=library -emit-library -O -wmo %S/Inputs/library1.swift %S/Inputs/library2.swift -o %t/wmo/library.%target-dylib-extension -swift-version 3
|
||||
// RUN: %target-build-swift %S/main.swift %t/wmo/library.%target-dylib-extension -I %t/wmo/ -o %t/wmo/main -swift-version 3
|
||||
|
||||
// RUN: mkdir -p %t/onone %t/wmo
|
||||
// RUN: %target-build-swift -emit-module -emit-module-path %t/onone/library.swiftmodule -module-name=library -emit-library %S/Inputs/library1.swift %S/Inputs/library2.swift -o %t/onone/library.%target-dylib-extension -swift-version 4
|
||||
// RUN: %target-build-swift %S/main.swift %t/onone/library.%target-dylib-extension -I %t/onone/ -o %t/onone/main -swift-version 4
|
||||
|
||||
@@ -1,123 +0,0 @@
|
||||
// RUN: %empty-directory(%t)
|
||||
// RUN: %target-build-swift -swift-version 3 %s -o %t/a.out
|
||||
// RUN: %target-run %t/a.out
|
||||
// REQUIRES: objc_interop
|
||||
// REQUIRES: executable_test
|
||||
// CoreMedia is not present on watchOS.
|
||||
// UNSUPPORTED: OS=watchos
|
||||
|
||||
import CoreMedia
|
||||
import AVFoundation
|
||||
import StdlibUnittest
|
||||
import StdlibUnittestFoundationExtras
|
||||
|
||||
var coreMedia = TestSuite("CoreMedia")
|
||||
|
||||
func equalCMTimeMappings(_ x: CMTimeMapping, _ y: CMTimeMapping) -> Bool {
|
||||
var xx = x, yy = y
|
||||
return memcmp(&xx, &yy, MemoryLayout<CMTimeMapping>.size) == 0
|
||||
}
|
||||
|
||||
coreMedia.test("NSValue bridging") {
|
||||
let time1 = CMTimeMake(181, 60)
|
||||
expectBridgeToNSValue(time1,
|
||||
nsValueInitializer: { NSValue(time: $0) },
|
||||
nsValueGetter: { $0.timeValue },
|
||||
equal: (==))
|
||||
let time2 = CMTimeMake(242, 60)
|
||||
let timeRange1 = CMTimeRangeFromTimeToTime(time1, time2)
|
||||
|
||||
expectBridgeToNSValue(timeRange1,
|
||||
nsValueInitializer: { NSValue(timeRange: $0) },
|
||||
nsValueGetter: { $0.timeRangeValue },
|
||||
equal: (==))
|
||||
|
||||
let time3 = CMTimeMake(303, 60)
|
||||
let timeRange2 = CMTimeRangeFromTimeToTime(time2, time3)
|
||||
let timeMapping = CMTimeMapping(source: timeRange1, target: timeRange2)
|
||||
expectBridgeToNSValue(timeMapping,
|
||||
nsValueInitializer: { NSValue(timeMapping: $0) },
|
||||
nsValueGetter: { $0.timeMappingValue },
|
||||
equal: equalCMTimeMappings)
|
||||
}
|
||||
|
||||
|
||||
var AVFoundationTests = TestSuite("AVFoundation_Swift3")
|
||||
|
||||
let boxedPixelFormat = NSNumber(value: kCVPixelFormatType_420YpCbCr8BiPlanarFullRange)
|
||||
|
||||
#if os(macOS) || os(iOS)
|
||||
|
||||
if #available(iOS 5, *) {
|
||||
AVFoundationTests.test("AVCaptureVideoDataOutput.availableVideoCVPixelFormatTypes") {
|
||||
func f(v: AVCaptureVideoDataOutput) -> Bool {
|
||||
return v.availableVideoCVPixelFormatTypes.contains(where: { e in
|
||||
if let e = e as? NSNumber, e == boxedPixelFormat {
|
||||
return true
|
||||
}
|
||||
else {
|
||||
return false
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#if os(iOS)
|
||||
|
||||
if #available(iOS 7, *) {
|
||||
AVFoundationTests.test("AVMetadataMachineReadableCodeObject.corners") {
|
||||
func f(m: AVMetadataMachineReadableCodeObject) -> [Any]! {
|
||||
return m.corners
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if #available(iOS 10, *) {
|
||||
AVFoundationTests.test("AVCaptureDeviceFormat.supportedColorSpaces") {
|
||||
func f(df: AVCaptureDeviceFormat) -> Bool {
|
||||
return df.supportedColorSpaces.contains(NSNumber(value: AVCaptureColorSpace.sRGB.rawValue))
|
||||
}
|
||||
}
|
||||
|
||||
AVFoundationTests.test("AVCapturePhotoOutput.supportedFlashModes") {
|
||||
func f(p: AVCapturePhotoOutput) -> Bool {
|
||||
return p.supportedFlashModes.contains(NSNumber(value: AVCaptureFlashMode.off.rawValue))
|
||||
}
|
||||
}
|
||||
|
||||
AVFoundationTests.test("AVCapturePhotoOutput.availablePhotoPixelFormatTypes") {
|
||||
func f(p: AVCapturePhotoOutput) -> Bool {
|
||||
return p.availablePhotoPixelFormatTypes.contains(boxedPixelFormat)
|
||||
}
|
||||
}
|
||||
|
||||
AVFoundationTests.test("AVCapturePhotoOutput.availableRawPhotoPixelFormatTypes") {
|
||||
func f(p: AVCapturePhotoOutput) -> Bool {
|
||||
return p.availableRawPhotoPixelFormatTypes.contains(boxedPixelFormat)
|
||||
}
|
||||
}
|
||||
|
||||
AVFoundationTests.test("AVCapturePhotoSettings.availablePreviewPhotoPixelFormatTypes") {
|
||||
func f(p: AVCapturePhotoSettings) -> Bool {
|
||||
return p.availablePreviewPhotoPixelFormatTypes.contains(boxedPixelFormat)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if #available(iOS 11, *) {
|
||||
AVFoundationTests.test("AVCaptureSynchronizedDataCollection/iteration") {
|
||||
func f(c: AVCaptureSynchronizedDataCollection) {
|
||||
for element in c {
|
||||
var element = element
|
||||
expectType(AVCaptureSynchronizedData.self, &element)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
runAllTests()
|
||||
@@ -1,52 +0,0 @@
|
||||
// RUN: %empty-directory(%t)
|
||||
// RUN: %target-build-swift -swift-version 3 %s -o %t/a.out
|
||||
// RUN: %target-run %t/a.out
|
||||
// REQUIRES: executable_test
|
||||
// REQUIRES: OS=macosx
|
||||
// REQUIRES: objc_interop
|
||||
|
||||
import AppKit
|
||||
import StdlibUnittest
|
||||
import StdlibUnittestFoundationExtras
|
||||
|
||||
let AppKitTests = TestSuite("AppKit_Swift3")
|
||||
|
||||
AppKitTests.test("NSEventMaskFromType") {
|
||||
let eventType: NSEventType = .keyDown
|
||||
let eventMask = NSEventMaskFromType(eventType)
|
||||
expectEqual(eventMask, .keyDown)
|
||||
}
|
||||
|
||||
AppKitTests.test("NSLayoutPriority") {
|
||||
let highPriority: NSLayoutPriority = NSLayoutPriorityDefaultHigh
|
||||
|
||||
let adjustedPriority1 = highPriority + 1
|
||||
let adjustedPriority1RawValue: Float = NSLayoutPriorityDefaultHigh + 1
|
||||
expectEqual(adjustedPriority1, adjustedPriority1RawValue)
|
||||
|
||||
let adjustedPriority2 = highPriority - 5.0
|
||||
let adjustedPriority2RawValue: Float = NSLayoutPriorityDefaultHigh - 5.0
|
||||
expectEqual(adjustedPriority2, adjustedPriority2RawValue)
|
||||
|
||||
let adjustedPriority3 = 5.0 + highPriority
|
||||
let adjustedPriority3RawValue: Float = 5.0 + NSLayoutPriorityDefaultHigh
|
||||
expectEqual(adjustedPriority3, adjustedPriority3RawValue)
|
||||
|
||||
// Inferred typing from result type
|
||||
let adjustedPriority4: NSLayoutPriority = NSLayoutPriorityDefaultHigh + 2.0
|
||||
let adjustedPriority4RawValue: Float = NSLayoutPriorityDefaultHigh + 2.0
|
||||
expectEqual(adjustedPriority4, adjustedPriority4RawValue)
|
||||
|
||||
// Comparable
|
||||
expectTrue(adjustedPriority1 > adjustedPriority2)
|
||||
expectTrue(adjustedPriority2 < adjustedPriority1)
|
||||
|
||||
// Compound assignment
|
||||
var variablePriority: NSLayoutPriority = NSLayoutPriorityDefaultHigh
|
||||
variablePriority += 1
|
||||
variablePriority -= 5.0
|
||||
let variablePriorityRawValue: Float = NSLayoutPriorityDefaultHigh + 1 - 5.0
|
||||
expectEqual(variablePriority, variablePriorityRawValue)
|
||||
}
|
||||
|
||||
runAllTests()
|
||||
@@ -1,37 +0,0 @@
|
||||
// RUN: %target-typecheck-verify-swift -swift-version 3
|
||||
|
||||
func f<T : SignedInteger>(x: T) {
|
||||
_ = T.addWithOverflow(x, x) // expected-error {{'addWithOverflow' is unavailable: Please use FixedWidthInteger protocol as a generic constraint and addingReportingOverflow(_:) method instead.}}
|
||||
_ = T.subtractWithOverflow(x, x) // expected-error {{'subtractWithOverflow' is unavailable: Please use FixedWidthInteger protocol as a generic constraint and subtractingReportingOverflow(_:) method instead.}}
|
||||
_ = T.multiplyWithOverflow(x, x) // expected-error {{'multiplyWithOverflow' is unavailable: Please use FixedWidthInteger protocol as a generic constraint and multipliedReportingOverflow(by:) method instead.}}
|
||||
_ = T.divideWithOverflow(x, x) // expected-error {{'divideWithOverflow' is unavailable: Please use FixedWidthInteger protocol as a generic constraint and dividedReportingOverflow(by:) method instead.}}
|
||||
_ = T.remainderWithOverflow(x, x) // expected-error {{'remainderWithOverflow' is unavailable: Please use FixedWidthInteger protocol as a generic constraint and remainderReportingOverflow(dividingBy:) method instead.}}
|
||||
}
|
||||
|
||||
func f<T : FixedWidthInteger>(x: T) {
|
||||
_ = T.addWithOverflow(x, x) // no error
|
||||
_ = T.subtractWithOverflow(x, x) // no error
|
||||
_ = T.multiplyWithOverflow(x, x) // no error
|
||||
_ = T.divideWithOverflow(x, x) // no error
|
||||
_ = T.remainderWithOverflow(x, x) // no error
|
||||
}
|
||||
|
||||
do {
|
||||
let _: IntMax = 0 // no error
|
||||
let _: UIntMax = 0 // no error
|
||||
}
|
||||
|
||||
func integer<T : Integer>(x: T) {} // no error
|
||||
func integerArithmetic<T : IntegerArithmetic>(x: T) {} // no error
|
||||
func signedNumber<T : SignedNumber>(x: T) {} // no error
|
||||
func absoluteValuable<T : AbsoluteValuable>(x: T) {} // no error
|
||||
func _signedInteger<T : _SignedInteger>(x: T) {} // no error
|
||||
|
||||
func absolutaValuable<T : SignedNumeric & Comparable>(x: T) {
|
||||
_ = T.abs(x) // no error
|
||||
}
|
||||
|
||||
func signedIntegerMaskingArithmetics<T : SignedInteger>(x: T) {
|
||||
_ = x &+ x // no error
|
||||
_ = x &- x // no error
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
//===--- MixedTypeArithmeticsDiagnostics3.swift ---------------------------===//
|
||||
//
|
||||
// This source file is part of the Swift.org open source project
|
||||
//
|
||||
// Copyright (c) 2014 - 2017 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: %target-typecheck-verify-swift -swift-version 3
|
||||
|
||||
|
||||
func mixedTypeArithemtics() {
|
||||
_ = (42 as Int64) + (0 as Int) // expected-warning {{'+' is deprecated}}
|
||||
|
||||
do {
|
||||
var x = Int8()
|
||||
x += (42 as Int) // expected-warning {{'+=' is deprecated}}
|
||||
}
|
||||
|
||||
_ = (42 as Int32) - (0 as Int) // expected-warning {{'-' is deprecated}}
|
||||
|
||||
do {
|
||||
var x = Int16()
|
||||
x -= (42 as Int) // expected-warning {{'-=' is deprecated}}
|
||||
}
|
||||
|
||||
// With Int on both sides should NOT result in warning
|
||||
do {
|
||||
var x = Int()
|
||||
x += (42 as Int)
|
||||
}
|
||||
}
|
||||
|
||||
func radar31909031() {
|
||||
let x = UInt64()
|
||||
let y = UInt64()
|
||||
_ = (x - y) < UInt64(42) // should not produce a mixed-type warning
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
// RUN: %target-swift-frontend -typecheck -swift-version 3 %s -verify
|
||||
|
||||
func testPopFirst() {
|
||||
var str = "abc"
|
||||
_ = str.popFirst() // expected-warning{{'popFirst()' is deprecated: Please use 'first', 'dropFirst()', or 'Substring.popFirst()'}}
|
||||
_ = str.characters.popFirst() // expected-warning{{'characters' is deprecated: Please use String directly}}
|
||||
// expected-warning@-1{{'popFirst()' is deprecated: Please use 'first', 'dropFirst()', or 'Substring.popFirst()'}}
|
||||
_ = str.unicodeScalars.popFirst() // expected-warning{{'popFirst()' is deprecated: Please use 'first', 'dropFirst()', or 'Substring.UnicodeScalarView.popFirst()'}}
|
||||
|
||||
var charView: String.CharacterView // expected-warning{{'CharacterView' is deprecated: Please use String directly}}
|
||||
charView = str.characters // expected-warning{{'characters' is deprecated: Please use String directly}}
|
||||
dump(charView)
|
||||
|
||||
var substr = str[...]
|
||||
_ = substr.popFirst() // ok
|
||||
_ = substr.characters.popFirst() // expected-warning{{'characters' is deprecated: Please use Substring directly}}
|
||||
_ = substr.unicodeScalars.popFirst() // ok
|
||||
|
||||
var charSubView: Substring.CharacterView // expected-warning{{'CharacterView' is deprecated: Please use Substring directly}}
|
||||
charSubView = substr.characters // expected-warning{{'characters' is deprecated: Please use Substring directly}}
|
||||
dump(charSubView)
|
||||
|
||||
var _ = String(str.utf8) ?? "" // expected-warning{{'init' is deprecated: Failable initializer was removed in Swift 4. When upgrading to Swift 4, please use non-failable String.init(_:UTF8View)}}
|
||||
var _ = String(str.utf8) // expected-warning{{'init' is deprecated: Failable initializer was removed in Swift 4. When upgrading to Swift 4, please use non-failable String.init(_:UTF8View)}}
|
||||
var _: String = String(str.utf8) // expected-error {{value of optional type 'String?' not unwrapped; did you mean to use '!' or '?'?}}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user