Skip to content

Commit

Permalink
more testcase updates for upcoming diagnostics change.
Browse files Browse the repository at this point in the history
Swift SVN r28409
  • Loading branch information
lattner committed May 11, 2015
1 parent ab65f6e commit 4366da9
Show file tree
Hide file tree
Showing 95 changed files with 660 additions and 581 deletions.
14 changes: 7 additions & 7 deletions test/1_stdlib/StringDiagnostics.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@ import Foundation

// Common pitfall: trying to subscript a string with integers.
func testIntSubscripting(s: String, i: Int) {
let c1 = s[i] // expected-error{{'subscript' is unavailable: cannot subscript String with an Int}}
let c2 = s[17] // expected-error{{'subscript' is unavailable: cannot subscript String with an Int}}
let c3 = s[i...i] // expected-error{{subscript' is unavailable: cannot subscript String with a range of Int}}
let c4 = s[17..<20] // expected-error{{subscript' is unavailable: cannot subscript String with a range of Int}}
let c5 = s[17...20] // expected-error{{subscript' is unavailable: cannot subscript String with a range of Int}}
let _ = s[i] // expected-error{{'subscript' is unavailable: cannot subscript String with an Int}}
let _ = s[17] // expected-error{{'subscript' is unavailable: cannot subscript String with an Int}}
let _ = s[i...i] // expected-error{{subscript' is unavailable: cannot subscript String with a range of Int}}
let _ = s[17..<20] // expected-error{{subscript' is unavailable: cannot subscript String with a range of Int}}
let _ = s[17...20] // expected-error{{subscript' is unavailable: cannot subscript String with a range of Int}}
}

func testNonAmbiguousStringComparisons() {
let names = ["Chris", "Alex", "Ewa", "Barry", "Daniella"]
var reversed1 = sorted(names, { s1, s2 in s1 > s2 })
var reversed2 = sorted(names, { s1, s2 in s1 as String > s2 })
var _ = sorted(names, { s1, s2 in s1 > s2 })
var _ = sorted(names, { s1, s2 in s1 as String > s2 })
}

func testAmbiguousStringComparisons(s: String) {
Expand Down
2 changes: 1 addition & 1 deletion test/BuildConfigurations/pound-if-inside-function-3.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

func foo() { // expected-note {{to match this opening '{'}}
#if BLAH
var x = 123;
var _ = 123;
#elseif !BLAH
#else
// expected-error@+2{{expected '}' at end of brace statement}}
Expand Down
2 changes: 1 addition & 1 deletion test/BuildConfigurations/pound-if-inside-function-4.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

func foo() { // expected-note {{to match this opening '{'}}
#if BLAH
var x = 123;
var _ = 123;
#elseif !BLAH
#else
#else // expected-error{{further conditions after #else are unreachable}}
Expand Down
6 changes: 3 additions & 3 deletions test/ClangModules/MixedSource/mixed-nsuinteger.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ var rr: UInt = userTypedObj.countByEnumeratingWithState(p, objects: pp, count: u

// Check exercising protocol conformance.
func gen<T:NSFastEnumeration>(t:T) {
var i: Int = 56
var p: UnsafeMutablePointer<NSFastEnumerationState> = nil
var pp: AutoreleasingUnsafeMutablePointer<AnyObject?> = nil
let i: Int = 56
let p: UnsafeMutablePointer<NSFastEnumerationState> = nil
let pp: AutoreleasingUnsafeMutablePointer<AnyObject?> = nil
t.countByEnumeratingWithState(p, objects: pp, count: i)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,6 @@ func testMacro() {
}

func testFoundationOverlay() {
let utf8 = NSUTF8StringEncoding // no ambiguity
let _ = NSUTF8StringEncoding // no ambiguity
let _: UInt = NSUTF8StringEncoding // and we should get the overlay version
}
6 changes: 3 additions & 3 deletions test/ClangModules/MixedSource/mixed-target-using-module.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ class Derived : Base {
}

func testMethod(container: Base, input: ForwardClass, inputProto: ForwardProto, inputPartial: PartialSubClass) {
let output: ForwardClass = container.unsafeOverrideReturn(input) // no-warning
let outputProto: ForwardProto = container.unsafeOverrideProtoReturn(inputProto) // no-warning
let outputPartial: PartialSubClass = container.unsafeOverridePartialSubReturn(inputPartial) // no-warning
let _: ForwardClass = container.unsafeOverrideReturn(input) // no-warning
let _: ForwardProto = container.unsafeOverrideProtoReturn(inputProto) // no-warning
let _: PartialSubClass = container.unsafeOverridePartialSubReturn(inputPartial) // no-warning
}


Expand Down
4 changes: 2 additions & 2 deletions test/ClangModules/availability.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func test_unavailable_func(x : NSObject) {
}

func test_deprecated_imported_as_unavailable(s:UnsafeMutablePointer<CChar>) {
let x = tmpnam(s) // expected-warning {{'tmpnam' is deprecated: Due to security concerns inherent in the design of tmpnam(3), it is highly recommended that you use mkstemp(3) instead.}}
let _ = tmpnam(s) // expected-warning {{'tmpnam' is deprecated: Due to security concerns inherent in the design of tmpnam(3), it is highly recommended that you use mkstemp(3) instead.}}
}

func test_NSInvocation(x: NSInvocation, // expected-error {{'NSInvocation' is unavailable}}
Expand All @@ -40,7 +40,7 @@ func test_class_avail(x:NSObject, obj: AnyObject) {

func test_unavailable_app_extension() {
// No expected error here. See corresponding App extension test.
let x = SomeCrazyAppExtensionForbiddenAPI() // no-error
let _ = SomeCrazyAppExtensionForbiddenAPI() // no-error
}

func test_swift_unavailable() {
Expand Down
2 changes: 1 addition & 1 deletion test/ClangModules/availability_app_extension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
import Foundation

func test_unavailable_app_extension() {
let x = SomeCrazyAppExtensionForbiddenAPI() // expected-error {{'SomeCrazyAppExtensionForbiddenAPI()' is unavailable: Not available in App Extensions}}
let _ = SomeCrazyAppExtensionForbiddenAPI() // expected-error {{'SomeCrazyAppExtensionForbiddenAPI()' is unavailable: Not available in App Extensions}}
}
2 changes: 1 addition & 1 deletion test/ClangModules/availability_macosx.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import Foundation
import AvailabilityExtras

func test_unavailable_because_deprecated() {
let x = NSRealMemoryAvailable() // expected-error {{APIs deprecated as of OS X 10.9 and earlier are unavailable in Swift}}
let _ = NSRealMemoryAvailable() // expected-error {{APIs deprecated as of OS X 10.9 and earlier are unavailable in Swift}}
}

func test_swift_unavailable_wins() {
Expand Down
2 changes: 1 addition & 1 deletion test/ClangModules/blocks_parse.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ func testNoEscape(@noescape f: @convention(block) () -> Void, nsStr: NSString,
// rdar://problem/19818617
nsStr.enumerateLinesUsingBlock(fStr) // okay due to @noescape

var x: Int = nsStr.enumerateLinesUsingBlock // expected-error{{'(@noescape (String!) -> Void) -> Void' is not convertible}}
var _: Int = nsStr.enumerateLinesUsingBlock // expected-error{{'(@noescape (String!) -> Void) -> Void' is not convertible}}
}
14 changes: 7 additions & 7 deletions test/ClangModules/cf.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func test4() {
func test5() {
let power: Unmanaged<CCPowerSupply> = .passUnretained(kCCPowerStandard)
assertUnmanaged(power)
let fridge = CCRefrigeratorCreate(power.takeUnretainedValue())
let _ = CCRefrigeratorCreate(power.takeUnretainedValue())
}

func test6() {
Expand All @@ -51,8 +51,8 @@ func test7() {
}

func test8(f: CCRefrigerator) {
let v1: CFTypeRef = f
let v2: AnyObject = f
let _: CFTypeRef = f
let _: AnyObject = f
}

func test9() {
Expand All @@ -73,17 +73,17 @@ func testProperty(k: Kitchen) {
}

func testTollFree0(mduct: MutableDuct) {
let ccmduct: CCMutableDuct = mduct
let _: CCMutableDuct = mduct

let duct: Duct = mduct
let ccduct: CCDuct = duct
let _: CCDuct = duct
}

func testTollFree1(ccmduct: CCMutableDuct) {
let mduct: MutableDuct = ccmduct
let _: MutableDuct = ccmduct

let ccduct: CCDuct = ccmduct
let duct: Duct = ccduct
let _: Duct = ccduct
}

func testChainedAliases(fridge: CCRefrigerator) {
Expand Down
36 changes: 18 additions & 18 deletions test/ClangModules/cfuncs_parse.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,35 +10,35 @@ func test_cfunc1(i: Int) {
}

func test_cfunc2(i: Int) {
var f = cfunc2(i, 17)
var f2 : Float = f
let f = cfunc2(i, 17)
var _ : Float = f
// FIXME: Should report this error: {{cannot convert the expression's type '$T3' to type 'CLong'}}
cfunc2(b:17, a:i) // expected-error{{cannot invoke 'cfunc2' with an argument list of type '(b: Int, a: Int)'}} expected-note {{expected an argument list of type '(Int, Int32)'}}
}

func test_cfunc3_a() {
var b = cfunc3( { (a : Double, b : Double) -> Double in a + b } )
var d : Double = b(1.5, 2.5)
var d1 : Double = b // expected-error{{'double_bin_op_block' is not convertible to 'Double'}}
let b = cfunc3( { (a : Double, b : Double) -> Double in a + b } )
var _ : Double = b(1.5, 2.5)
var _ : Double = b // expected-error{{'double_bin_op_block' is not convertible to 'Double'}}
}

func test_cfunc3_b() {
var b = cfunc3( { a, b in a + b } )
var d : Double = b(1.5, 2.5)
var d1 : Double = b // expected-error{{'double_bin_op_block' is not convertible to 'Double'}}
let b = cfunc3( { a, b in a + b } )
var _ : Double = b(1.5, 2.5)
var _ : Double = b // expected-error{{'double_bin_op_block' is not convertible to 'Double'}}
}

func test_cfunc3_c() {
var b = cfunc3({ $0 + $1 })
var d : Double = b(1.5, 2.5)
var d1 : Double = b // expected-error{{'double_bin_op_block' is not convertible to 'Double'}}
let b = cfunc3({ $0 + $1 })
var _ : Double = b(1.5, 2.5)
var _ : Double = b // expected-error{{'double_bin_op_block' is not convertible to 'Double'}}
}

func test_cfunc3_d() {
var x: Double = 0
var y: Double = 0
var z: Double? = cfunc3(nil)?(x, y)
var w: Double = cfunc3(nil)!(x, y)
let x: Double = 0
let y: Double = 0
var _: Double? = cfunc3(nil)?(x, y)
var _: Double = cfunc3(nil)!(x, y)
}

func test_cfunc4() {
Expand All @@ -51,11 +51,11 @@ func test_pow() {
}

func test_puts(s: String) {
var i = s.withCString { puts($0) + 32 };
var _ = s.withCString { puts($0) + 32 };
}

func test_fopen(filename: String) -> CInt {
var file = filename.withCString { fopen($0, "r") }
let file = filename.withCString { fopen($0, "r") }
return file.memory.inode
}

Expand Down Expand Up @@ -103,7 +103,7 @@ func test_pointer() {
param_const_void_pointer(fa)
// FIXME: param_const_void_pointer([1.0, 2.0, 3.0])

var op = COpaquePointer()
let op = COpaquePointer()
opaque_pointer_param(op)
}

Expand Down
2 changes: 1 addition & 1 deletion test/ClangModules/cstring_parse.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@
import cfuncs

func test_puts(s: String) {
var i = puts(s) + 32
var _ = puts(s) + 32
}
49 changes: 28 additions & 21 deletions test/ClangModules/ctypes_parse.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ func testAnonEnum() {
var a = AnonConst1
a = AnonConst2
#if arch(i386) || arch(arm)
var a2: CUnsignedLongLong = a
var _: CUnsignedLongLong = a
#elseif arch(x86_64) || arch(arm64)
var a2: CUnsignedLong = a
var _: CUnsignedLong = a
#else
__portMe()
#endif
Expand All @@ -40,7 +40,7 @@ func testAnonEnum() {
func testAnonEnumSmall() {
var a = AnonConstSmall1
a = AnonConstSmall2
var a2: Int = a
var _: Int = a
}

func testPoint() -> Float {
Expand All @@ -57,14 +57,14 @@ func testAnonStructs() {
}

func testBitfieldMembers() {
var a: StructWithBitfields
var _: StructWithBitfields
// TODO: Expose the bitfields as properties.
}

// FIXME: Import arrays as real array-looking things.

func testArrays() {
var fes: NSFastEnumerationState
let fes: NSFastEnumerationState
var ulong: CUnsignedLong
var pulong: UnsafeMutablePointer<CUnsignedLong>

Expand All @@ -75,14 +75,15 @@ func testArrays() {
ulong = fes.extra.2
ulong = fes.extra.3
ulong = fes.extra.4
_ = ulong; _ = pulong
}

// FIXME: Import pointers to opaque types as unique types.

func testPointers() {
var hWnd: HWND = nil
var cfstr: CFString? = nil
var cfty: CFTypeRef? = cfstr
var _: HWND = nil
let cfstr: CFString? = nil
var _: CFTypeRef? = cfstr
}

// Ensure that imported structs can be extended, even if typedef'ed on the C
Expand Down Expand Up @@ -123,11 +124,13 @@ extension CGRect {
}

func testFuncStructDisambiguation() {
var a : funcOrStruct
let a : funcOrStruct
var i = funcOrStruct()
i = 5
_ = i
var a2 = funcOrStruct(i: 5)
a2 = a
_ = a2
}

func testVoid() {
Expand Down Expand Up @@ -159,31 +162,35 @@ func testImportStdintTypes() {
var t10_unqual : UInt = uintptr_t_test
t9_unqual = word
t10_unqual = uword
_ = t9_unqual
_ = t10_unqual

var t9_qual : intptr_t = 0 // no-warning
var t10_qual : uintptr_t = 0 // no-warning
t9_qual = word
t10_qual = uword
_ = t9_qual
_ = t10_qual
}

func testImportStddefTypes() {
var t1_unqual: Int = ptrdiff_t_test
var t2_unqual: Int = size_t_test
var t3_unqual: Int = rsize_t_test
let t1_unqual: Int = ptrdiff_t_test
let t2_unqual: Int = size_t_test
let t3_unqual: Int = rsize_t_test

var t1_qual: ctypes.ptrdiff_t = t1_unqual
var t2_qual: ctypes.size_t = t2_unqual
var t3_qual: ctypes.rsize_t = t3_unqual
let _: ctypes.ptrdiff_t = t1_unqual
let _: ctypes.size_t = t2_unqual
var _: ctypes.rsize_t = t3_unqual
}

func testImportSysTypesTypes() {
var t1_unqual: Int = ssize_t_test
var t1_qual: ctypes.ssize_t = t1_unqual
let t1_unqual: Int = ssize_t_test
var _: ctypes.ssize_t = t1_unqual
}

func testImportCFTypes() {
var t1_unqual: Int = CFIndex_test
var t1_qual: CoreFoundation.CFIndex = t1_unqual
let t1_unqual: Int = CFIndex_test
var _: CoreFoundation.CFIndex = t1_unqual
}

func testImportOSTypesTypes() {
Expand Down Expand Up @@ -238,10 +245,10 @@ func testFunctionPointers() {
let fp = getFunctionPointer()
useFunctionPointer(fp)

let explicitFP: @convention(c) (CInt) -> CInt = fp
let _: @convention(c) (CInt) -> CInt = fp

let wrapper: FunctionPointerWrapper = FunctionPointerWrapper(a: nil, b: nil)
let wrapper2 = FunctionPointerWrapper(a: fp, b: fp)
let _ = FunctionPointerWrapper(a: fp, b: fp)
useFunctionPointer(wrapper.a)
let _: @convention(c) (CInt) -> CInt = wrapper.b

Expand Down
6 changes: 3 additions & 3 deletions test/ClangModules/ctypes_parse_union.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ func useStructWithBitfields(mrm: ModRM) -> ModRM {
// Incompletely imported structs shouldn't have elementwise initializers.
// They can still be zero-initialized using the default initializer.
func constructStructWithBitfields(x: CUnsignedInt) {
let a: StructWithBitfields = StructWithBitfields()
let b: StructWithBitfields = StructWithBitfields(First: x) // expected-error{{}}
let _: StructWithBitfields = StructWithBitfields()
let _: StructWithBitfields = StructWithBitfields(First: x) // expected-error{{}}
// TODO: Fully import bitfields.
let c: StructWithBitfields = StructWithBitfields(First: x, Second: x, Third: x) // expected-error{{}}
let _: StructWithBitfields = StructWithBitfields(First: x, Second: x, Third: x) // expected-error{{}}
}
Loading

0 comments on commit 4366da9

Please sign in to comment.