Files
swift-mirror/test/ClangModules/blocks_parse.swift
Joe Groff c0a2994564 AST: Start printing function types with @convention instead of old attributes.
And update tests to match.

Swift SVN r27262
2015-04-13 22:51:34 +00:00

28 lines
1.2 KiB
Swift

// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -parse -verify %s
// REQUIRES: objc_interop
import blocks
import Foundation
var someNSString : NSString
func useString(s: String) {}
dispatch_async(dispatch_get_current_queue()) { }
someNSString.enumerateLinesUsingBlock {(s:String?) in }
someNSString.enumerateLinesUsingBlock {s in }
someNSString.enumerateLinesUsingBlock({ useString($0) })
dispatch_async(dispatch_get_current_queue(), /*not a block=*/()) // expected-error{{cannot invoke 'dispatch_async' with an argument list of type '(dispatch_queue_t, ())'}} expected-note {{expected an argument list of type '(dispatch_queue_t, dispatch_block_t!)'}}
func testNoEscape(@noescape f: @convention(block) () -> Void, nsStr: NSString,
@noescape fStr: (String!) -> Void) {
dispatch_async(dispatch_get_current_queue(), f) // expected-error{{invalid use of non-escaping function in escaping context '@convention(block) () -> Void'}}
dispatch_sync(dispatch_get_current_queue(), f) // okay: dispatch_sync is noescape
// rdar://problem/19818617
nsStr.enumerateLinesUsingBlock(fStr) // okay due to @noescape
var x: Int = nsStr.enumerateLinesUsingBlock // expected-error{{'(@noescape (String!) -> Void) -> Void' is not convertible}}
}