Files
swift-mirror/test/ClangImporter/blocks_parse.swift
Mark Lacey 8b55a0f61b SE-0054: Rework diagnostics for IUOs and revise Swift 3 /4 semantics.
For Swift 3 / 4:

Deprecate the spelling "ImplicitlyUnwrappedOptional", emitting a warning
and suggesting "!" in places where they are allowed according to
SE-0054.

In places where SE-0054 disallowed IUOs but we continued to accept them
in previous compilers, emit a warning suggesting "Optional" or "?"  as
an alternative depending on context and treat the IUO as an Optional,
noting this in the diagnostic.

For Swift 5:

Treat "ImplicitlyUnwrappedOptional" as an error, suggesting
"!" in places where they are allowed by SE-0054.

In places where SE-0054 disallowed IUOs, emit an error suggestion
"Optional" or "?" as an alternative depending on context.
2017-11-18 11:41:53 +09:00

50 lines
1.5 KiB
Swift

// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -typecheck -verify %s
// REQUIRES: objc_interop
import blocks
import Foundation
var someNSString : NSString
func useString(_ s: String) {}
accepts_block { }
someNSString.enumerateLines {(s:String?) in }
someNSString.enumerateLines {s in }
someNSString.enumerateLines({ useString($0) })
accepts_block(/*not a block=*/()) // expected-error{{cannot convert value of type '()' to expected argument type 'my_block_t' (aka '() -> ()'}}
func testNoEscape(f: @convention(block) () -> Void, nsStr: NSString,
fStr: (String?) -> Void) {
accepts_noescape_block(f)
accepts_noescape_block(f)
// Please see related tests in PrintAsObjC/imported-block-typedefs.swift.
// rdar://problem/19818617
nsStr.enumerateLines(fStr) // okay due to @noescape
_ = nsStr.enumerateLines as Int // expected-error{{cannot convert value of type '((String) -> Void) -> Void' to type 'Int' in coercion}}
}
func checkTypeImpl<T>(_ a: inout T, _: T.Type) {}
do {
var blockOpt = blockWithoutNullability()
checkTypeImpl(&blockOpt, Optional<my_block_t>.self)
var _: my_block_t = blockWithoutNullability()
}
do {
var block = blockWithNonnull()
checkTypeImpl(&block, my_block_t.self)
}
do {
var blockOpt = blockWithNullUnspecified()
checkTypeImpl(&blockOpt, Optional<my_block_t>.self)
var _: my_block_t = blockWithNullUnspecified()
}
do {
var block = blockWithNullable()
checkTypeImpl(&block, Optional<my_block_t>.self)
}