mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
[stdlib] replace precondition with guard-else-_assertionFailure
This commit is contained in:
committed by
Hassan
parent
1d4f220ed4
commit
e87a3e30ca
@@ -254,23 +254,29 @@ extension _ArrayBuffer {
|
||||
internal func _typeCheckSlowPath(_ index: Int) {
|
||||
if _fastPath(_isNative) {
|
||||
let element: AnyObject = cast(toBufferOf: AnyObject.self)._native[index]
|
||||
precondition(
|
||||
element is Element,
|
||||
"""
|
||||
Down-casted Array element failed to match the target type
|
||||
Expected \(Element.self) but found \(type(of: element))
|
||||
"""
|
||||
)
|
||||
guard element is Element else {
|
||||
_assertionFailure(
|
||||
"Fatal error",
|
||||
"""
|
||||
Down-casted Array element failed to match the target type
|
||||
Expected \(Element.self) but found \(type(of: element))
|
||||
""",
|
||||
flags: _fatalErrorFlags()
|
||||
)
|
||||
}
|
||||
}
|
||||
else {
|
||||
let element = _nonNative[index]
|
||||
precondition(
|
||||
element is Element,
|
||||
"""
|
||||
NSArray element failed to match the Swift Array Element type
|
||||
Expected \(Element.self) but found \(type(of: element))
|
||||
"""
|
||||
)
|
||||
guard element is Element else {
|
||||
_assertionFailure(
|
||||
"Fatal error",
|
||||
"""
|
||||
NSArray element failed to match the Swift Array Element type
|
||||
Expected \(Element.self) but found \(type(of: element))
|
||||
""",
|
||||
flags: _fatalErrorFlags()
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -505,23 +511,29 @@ extension _ArrayBuffer {
|
||||
_native._checkValidSubscript(i)
|
||||
|
||||
element = cast(toBufferOf: AnyObject.self)._native[i]
|
||||
precondition(
|
||||
element is Element,
|
||||
"""
|
||||
Down-casted Array element failed to match the target type
|
||||
Expected \(Element.self) but found \(type(of: element))
|
||||
"""
|
||||
)
|
||||
guard element is Element else {
|
||||
_assertionFailure(
|
||||
"Fatal error",
|
||||
"""
|
||||
Down-casted Array element failed to match the target type
|
||||
Expected \(Element.self) but found \(type(of: element))
|
||||
""",
|
||||
flags: _fatalErrorFlags()
|
||||
)
|
||||
}
|
||||
} else {
|
||||
// ObjC arrays do their own subscript checking.
|
||||
element = _nonNative[i]
|
||||
precondition(
|
||||
element is Element,
|
||||
"""
|
||||
NSArray element failed to match the Swift Array Element type
|
||||
Expected \(Element.self) but found \(type(of: element))
|
||||
"""
|
||||
)
|
||||
guard element is Element else {
|
||||
_assertionFailure(
|
||||
"Fatal error",
|
||||
"""
|
||||
NSArray element failed to match the Swift Array Element type
|
||||
Expected \(Element.self) but found \(type(of: element))
|
||||
""",
|
||||
flags: _fatalErrorFlags()
|
||||
)
|
||||
}
|
||||
}
|
||||
return element
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user