Skip to content

Commit 9cd12f0

Browse files
authored
Merge pull request #83472 from xymus/scalar-reference
PrintAsClang: Fix crash and document `Unicode.Scalar` printing behavior
2 parents 6d042ae + 54362d8 commit 9cd12f0

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

lib/PrintAsClang/DeclAndTypePrinter.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2406,7 +2406,8 @@ class DeclAndTypePrinter::Implementation
24062406
}
24072407

24082408
void maybePrintTagKeyword(const TypeDecl *NTD) {
2409-
if (auto *ED = dyn_cast<EnumDecl>(NTD); !NTD->hasClangNode()) {
2409+
auto *ED = dyn_cast<EnumDecl>(NTD);
2410+
if (ED && !NTD->hasClangNode()) {
24102411
if (ED->getAttrs().hasAttribute<CDeclAttr>()) {
24112412
// We should be able to use the tag macro for all printed enums but
24122413
// for now restrict it to @cdecl to guard it behind the feature flag.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// RUN: %empty-directory(%t)
2+
3+
// Test the behavior of printing Unicode.Scalar in the compatibility header.
4+
// This is wrong, it should either be rejected and considered non-representable
5+
// or actually be printed using a C / Objective-C compatible type.
6+
7+
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) \
8+
// RUN: %s -emit-module -verify -o %t \
9+
// RUN: -emit-clang-header-path %t/compat.h
10+
// RUN: %FileCheck %s --input-file %t/compat.h
11+
12+
@_cdecl("referencesScalar")
13+
func referencesScalar() -> Unicode.Scalar { fatalError() }
14+
// CHECK: SWIFT_EXTERN Scalar referencesScalar(void)

0 commit comments

Comments
 (0)