mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Merge pull request #81492 from kubamracek/import-values-apinotes
[ClangImporter] Fix enum conversion type when importing global values (unwrap if needed)
This commit is contained in:
@@ -4630,9 +4630,14 @@ namespace {
|
||||
auto convertKind = ConstantConvertKind::None;
|
||||
// Request conversions on enums, and swift_wrapper((enum/struct))
|
||||
// types
|
||||
if (decl->getType()->isEnumeralType())
|
||||
convertKind = ConstantConvertKind::Construction;
|
||||
else if (findSwiftNewtype(decl, Impl.getClangSema(),
|
||||
if (decl->getType()->isEnumeralType()) {
|
||||
if (type->getEnumOrBoundGenericEnum()) {
|
||||
// When importing as an enum, also apply implicit force unwrap
|
||||
convertKind = ConstantConvertKind::ConstructionWithUnwrap;
|
||||
} else {
|
||||
convertKind = ConstantConvertKind::Construction;
|
||||
}
|
||||
} else if (findSwiftNewtype(decl, Impl.getClangSema(),
|
||||
Impl.CurrentVersion))
|
||||
convertKind = ConstantConvertKind::Construction;
|
||||
|
||||
|
||||
38
test/ClangImporter/const_values_apinotes.swift
Normal file
38
test/ClangImporter/const_values_apinotes.swift
Normal file
@@ -0,0 +1,38 @@
|
||||
// RUN: %empty-directory(%t/src)
|
||||
// RUN: split-file %s %t/src
|
||||
|
||||
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) %t/src/main.swift \
|
||||
// RUN: -module-name main -I %t/src -emit-sil -sil-verify-all | %FileCheck %s
|
||||
|
||||
//--- test.h
|
||||
|
||||
typedef long NSInteger;
|
||||
typedef enum XCTestErrorCode: NSInteger {
|
||||
XCTestErrorCodeTimeoutWhileWaiting,
|
||||
XCTestErrorCodeFailureWhileWaiting,
|
||||
} XCTestErrorCode;
|
||||
|
||||
static XCTestErrorCode const XCTestErrorUnsupported = (XCTestErrorCode)109;
|
||||
|
||||
//--- Framework.apinotes
|
||||
---
|
||||
Name: Framework
|
||||
Tags:
|
||||
- Name: XCTestErrorCode
|
||||
NSErrorDomain: XCTestErrorDomain
|
||||
|
||||
//--- module.modulemap
|
||||
module Framework {
|
||||
header "test.h"
|
||||
}
|
||||
|
||||
//--- main.swift
|
||||
import Framework
|
||||
func foo() {
|
||||
print(XCTestError.timeoutWhileWaiting)
|
||||
print(XCTestErrorUnsupported)
|
||||
}
|
||||
|
||||
|
||||
// CHECK: // XCTestErrorUnsupported.getter
|
||||
// CHECK: sil shared [transparent] @$sSo22XCTestErrorUnsupportedSo0aB4CodeVvg : $@convention(thin) () -> XCTestError {
|
||||
Reference in New Issue
Block a user