Skip to content

Tests for SR-2289 #4107

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 9, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 47 additions & 2 deletions test/1_stdlib/Casts.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@
/// Contains tests for conversions between types which shouldn't trap.
///
// -----------------------------------------------------------------------------
// RUN: %target-run-stdlib-swift
// RUN: %target-run-simple-swift
// REQUIRES: executable_test

import StdlibUnittest

#if _runtime(_ObjC)
import Foundation
#endif

let CastsTests = TestSuite("Casts")

Expand Down Expand Up @@ -46,4 +48,47 @@ CastsTests.test("No overrelease of existential boxes in failed casts") {
bar(err)
}

extension Int : P {}

#if _runtime(_ObjC)
extension CFBitVector : P {
static func makeImmutable(from values: Array<UInt8>) -> CFBitVector {
return CFBitVectorCreate(/*allocator:*/ nil, values, values.count * 8)
}
}

extension CFMutableBitVector {
static func makeMutable(from values: Array<UInt8>) -> CFMutableBitVector {
return CFBitVectorCreateMutableCopy(
/*allocator:*/ nil,
/*capacity:*/ 0,
CFBitVector.makeImmutable(from: values))
}
}

func isP<T>(_ t: T) -> Bool {
return t is P
}

CastsTests.test("Dynamic casts of CF types to protocol existentials") {
expectTrue(isP(10 as Int))

// FIXME: SR-2289: dynamic casting of CF types to protocol existentials
// should work, but there is a bug in the runtime that prevents them from
// working.
if !_isDebugAssertConfiguration() {
// FIXME: this test should not crash. It currently crashes in optimized
// mode because the optimizer assumes that the type conforms, but then the
// runtime disagrees.
expectCrashLater()
}
expectFailure {
expectTrue(isP(CFBitVector.makeImmutable(from: [10, 20])))
}
expectFailure {
expectTrue(isP(CFMutableBitVector.makeMutable(from: [10, 20])))
}
}
#endif

runAllTests()