stdlib/Dictionary: add tests for trapping during bridging a Dictionary

whose KeyType is not NSCopyable

Swift SVN r18259
This commit is contained in:
Dmitri Hrybenko
2014-05-17 17:24:58 +00:00
parent 6808737952
commit 5c453ce2bc
2 changed files with 54 additions and 3 deletions

View File

@@ -696,7 +696,11 @@ func _convertDictionaryToNSDictionary<KeyType, ValueType>(
// Avoid calling the runtime.
bridgedValue = _reinterpretCastToAnyObject(value)
} else {
bridgedValue = bridgeToObjectiveC(value)!
if let theBridgedValue: AnyObject = bridgeToObjectiveC(value) {
bridgedValue = theBridgedValue
} else {
_preconditionFailure("Dictionary to NSDictionary bridging: value failed to bridge")
}
}
// NOTE: the just-bridged key is copied here. It would be nice to avoid
@@ -707,7 +711,12 @@ func _convertDictionaryToNSDictionary<KeyType, ValueType>(
if let nsCopyingKey = bridgedKey as NSCopying {
result[nsCopyingKey] = bridgedValue
} else {
_fatalError("key bridged to an object that does not conform to NSCopying")
// This check is considered not comprehensive because on a different
// code path -- when KeyType bridges verbatim -- we are not doing it
// eagerly. Instead, the message send will fail at runtime when
// NSMutableDictionary attempts to copy the key that does not conform
// to NSCopying.
_debugPreconditionFailure("key bridged to an object that does not conform to NSCopying")
}
}
return reinterpretCast(result)