Files
swift-mirror/test/ClangModules/objc_failable_inits.swift
Chris Lattner 1ad24fdfc2 rework how 'as' casts are diagnosed, removing a special case from CSApply and
allowing these failures to hook into other diagnostic goodies (e.g. the
"did you mean to use '!' or '?'?" cases showing in the testsuite).  That said,
by itself this doesn't have a huge impact, but avoids regressions with other
pending changes.


Swift SVN r31289
2015-08-18 04:35:41 +00:00

29 lines
800 B
Swift

// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -parse %s -verify
// REQUIRES: objc_interop
import Foundation
func testDictionary() {
// -[NSDictionary init] returns non-nil.
var dictNonOpt = NSDictionary()
if dictNonOpt == nil { } // expected-error{{value of type 'NSDictionary' can never be nil, comparison isn't allowed}}
}
func testString() throws {
// Optional
let stringOpt = NSString(path: "blah", encoding: 0)
_ = stringOpt as NSString // expected-error{{value of optional type 'NSString?' not unwrapped; did you mean to use '!' or '?'?}}
// Implicitly unwrapped optional
let stringIUO = NSString(path: "blah")
if stringIUO == nil { }
_ = stringIUO as NSString
}
func testHive() {
let hiveIUO = Hive()
if hiveIUO == nil { }
_ = hiveIUO as Hive
}