mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
[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;
|
auto convertKind = ConstantConvertKind::None;
|
||||||
// Request conversions on enums, and swift_wrapper((enum/struct))
|
// Request conversions on enums, and swift_wrapper((enum/struct))
|
||||||
// types
|
// types
|
||||||
if (decl->getType()->isEnumeralType())
|
if (decl->getType()->isEnumeralType()) {
|
||||||
convertKind = ConstantConvertKind::Construction;
|
if (type->getEnumOrBoundGenericEnum()) {
|
||||||
else if (findSwiftNewtype(decl, Impl.getClangSema(),
|
// 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))
|
Impl.CurrentVersion))
|
||||||
convertKind = ConstantConvertKind::Construction;
|
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