mirror of
https://github.com/apple/swift.git
synced 2026-10-20 19:13:47 +02:00
See https://github.com/swiftlang/swift/issues/88767. SILDynamicCastInst::getLoweredBridgedTargetObjectType wrapped the formal bridged target type via SILType::getPrimitiveObjectType, which preserves DynamicSelfType. SIL type lowering strips DynamicSelfType (LoweredRValueTypeVisitor::visitDynamicSelfType), so consumers that compared the helper's result against a lowered SIL type disagreed whenever an as? cast's target was Self inside an extension of a bridgeable class (e.g. NSDecimalNumber, NSString). An assertion in CastOptimizer::computeFinalCastedValue tripped, crashing the compiler. Route the helper through the containing SILFunction's TypeConverter so DynamicSelfType is stripped consistently with every other cast-type consumer. Both call sites (computeFinalCastedValue and convertObjectToLoadableBridgeableType) get the fix without further changes. This follows the pattern established in #85128 for the analogous inconsistency in canOptimizeCast.
21 lines
429 B
Swift
21 lines
429 B
Swift
// RUN: %target-swift-frontend -emit-sil -verify %s
|
|
// RUN: %target-swift-frontend -O -emit-sil -verify %s
|
|
|
|
// REQUIRES: objc_interop
|
|
|
|
// Regression test for https://github.com/swiftlang/swift/issues/88767
|
|
|
|
import Foundation
|
|
|
|
extension NSDecimalNumber {
|
|
static func roundtrip(_ d: Decimal) -> Self? {
|
|
return d as? Self
|
|
}
|
|
}
|
|
|
|
extension NSString {
|
|
static func roundtrip(_ s: String) -> Self? {
|
|
return s as? Self
|
|
}
|
|
}
|