Files
swift-mirror/test/ClangModules/nullability.swift
Dmitri Hrybenko f43843f25c tests: use the new substitution for the mock SDK
This is required to correctly use the mock SDK when the SDK overlay is
built and tested separately.  (Otherwise, the mock SDK might not get
used, because the overlay SDK options would expand from the
%-substitution, appear first on the command line, and shadow the mock
SDK in the search path).

Swift SVN r25185
2015-02-11 18:57:29 +00:00

58 lines
2.6 KiB
Swift

// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -parse -I %S/Inputs/custom-modules %s -verify
// REQUIRES: objc_interop
import nullability;
import CoreCooling
func testSomeClass(sc: SomeClass, osc: SomeClass?) {
var ao1: AnyObject = sc.methodA(osc)
if sc.methodA(osc) == nil { } // expected-error{{binary operator '==' cannot be applied to operands of type 'AnyObject' and 'nil'}}
var ao2: AnyObject = sc.methodB(nil)
if sc.methodA(osc) == nil { } // expected-error{{binary operator '==' cannot be applied to operands of type 'AnyObject' and 'nil'}}
var ao3: AnyObject = sc.property // expected-error{{value of optional type 'AnyObject?' not unwrapped; did you mean to use '!' or '?'?}}
var ao3_ok: AnyObject? = sc.property // okay
var ao4: AnyObject = sc.methodD()
if sc.methodD() == nil { } // expected-error{{binary operator '==' cannot be applied to operands of type 'AnyObject' and 'nil'}}
sc.methodE(sc)
sc.methodE(osc) // expected-error{{value of optional type 'SomeClass?' not unwrapped; did you mean to use '!' or '?'?}}
sc.methodF(sc, second: sc)
sc.methodF(osc, second: sc) // expected-error{{value of optional type 'SomeClass?' not unwrapped; did you mean to use '!' or '?'?}}
sc.methodF(sc, second: osc) // expected-error{{value of optional type 'SomeClass?' not unwrapped; did you mean to use '!' or '?'?}}
sc.methodG(sc, second: sc)
sc.methodG(osc, second: sc) // expected-error{{value of optional type 'SomeClass?' not unwrapped; did you mean to use '!' or '?'?}}
sc.methodG(sc, second: osc)
let ci: CInt = 1
var sc2 = SomeClass(int: ci)
var sc2a: SomeClass = sc2
if sc2 == nil { } // expected-error{{binary operator '==' cannot be applied to operands of type 'SomeClass' and 'nil'}}
var sc3 = SomeClass(double: 1.5)
if sc3 == nil { } // okay
var sc3a: SomeClass = sc3 // expected-error{{value of optional type 'SomeClass?' not unwrapped}}
var sc4 = sc.returnMe()
var sc4a: SomeClass = sc4
if sc4 == nil { } // expected-error{{binary operator '==' cannot be applied to operands of type 'SomeClass' and 'nil'}}
}
// Nullability with CF types.
func testCF(fridge: CCRefrigerator) {
CCRefrigeratorOpenDoSomething(fridge) // okay
CCRefrigeratorOpenDoSomething(nil) // expected-error{{cannot invoke 'CCRefrigeratorOpenDoSomething' with an argument list of type '(nil)'}}
// expected-note@-1{{expected an argument list of type '(CCRefrigerator)'}}
CCRefrigeratorOpenMaybeDoSomething(fridge) // okay
CCRefrigeratorOpenMaybeDoSomething(nil) // okay
CCRefrigeratorOpenMaybeDoSomething(5) // expected-error{{cannot invoke}}
// expected-note@-1{{argument list of type '(CCRefrigerator?)'}}
}