diff --git a/lib/ClangImporter/ImportDecl.cpp b/lib/ClangImporter/ImportDecl.cpp index 7ddbb3383ec20..6ef169042a1f6 100644 --- a/lib/ClangImporter/ImportDecl.cpp +++ b/lib/ClangImporter/ImportDecl.cpp @@ -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; diff --git a/test/ClangImporter/const_values_apinotes.swift b/test/ClangImporter/const_values_apinotes.swift new file mode 100644 index 0000000000000..d8b00bae165e4 --- /dev/null +++ b/test/ClangImporter/const_values_apinotes.swift @@ -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 {