Skip to content

Commit 6e68130

Browse files
authored
Merge pull request #85412 from kubamracek/section-uint8
Support 'as UInt8' in @section expressions
2 parents 11356ac + ac49d93 commit 6e68130

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

lib/Sema/LegalConstExprVerifier.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,16 @@ checkSupportedWithSectionAttribute(const Expr *expr,
176176
// Non-InlineArray arrays are not allowed
177177
return std::make_pair(expr, TypeNotSupported);
178178
}
179+
180+
// Coerce expressions to UInt8 are allowed (to support @DebugDescription)
181+
if (const CoerceExpr *coerceExpr = dyn_cast<CoerceExpr>(expr)) {
182+
auto coerceType = coerceExpr->getType();
183+
if (coerceType && coerceType->isUInt8()) {
184+
expressionsToCheck.push_back(coerceExpr->getSubExpr());
185+
continue;
186+
}
187+
return std::make_pair(expr, TypeNotSupported);
188+
}
179189

180190
// Operators are not allowed in @section expressions
181191
if (isa<BinaryExpr>(expr)) {

test/ConstValues/SectionSyntactic.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@
3535
// non-literal expressions (should be rejected)
3636
@section("mysection") let invalidNonLiteral1 = Int.max
3737
// expected-error@-1{{not supported in a constant expression}}
38-
@section("mysection") let invalidNonLiteral2 = UInt8(42)
39-
// expected-error@-1{{not supported in a constant expression}}
38+
@section("mysection") let invalidNonLiteral2 = UInt64(42)
39+
// expected-error@-1{{unsupported type in a constant expression}}
4040
@section("mysection") let invalidNonLiteral3 = true.hashValue
4141
// expected-error@-1{{not supported in a constant expression}}
4242

@@ -85,6 +85,7 @@ enum E { case a }
8585
@section("mysection") let tuple1 = (1, 2, 3, 2.718, true) // ok
8686
@section("mysection") let tuple2: (Int, Float, Bool) = (42, 3.14, false) // ok
8787
@section("mysection") let tuple3 = (foo, bar) // ok (function references in tuple)
88+
@section("mysection") let tuple4 = (1 as UInt8, 2 as UInt8, 3 as UInt8) // ok
8889

8990
// invalid tuples (should be rejected)
9091
@section("mysection") let invalidTuple1 = (1, 2, Int.max)

0 commit comments

Comments
 (0)