Files
swift-mirror/test/SILOptimizer/issue-88767.swift
alexander.azarov 3661db5fc5 [SIL] Lower bridged target through TypeConverter in getLoweredBridgedTargetObjectType
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.
2026-05-01 10:54:06 -04:00

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
}
}