Skip to content

Commit 07c7264

Browse files
committed
Fix hex string spec examples
Since spec examples are wrapped in a main function, the variables need to be annotated `static` in this case
1 parent b0a83c2 commit 07c7264

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

spec/expression.dd

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2023,23 +2023,23 @@ $(H3 $(LNAME2 hex_string_literals, Hex String Literals))
20232023

20242024
$(SPEC_RUNNABLE_EXAMPLE_RUN
20252025
-------------
2026-
immutable uint[] data = cast(immutable uint[]) x"AABBCCDD";
2026+
static immutable uint[] data = cast(immutable uint[]) x"AABBCCDD";
20272027
static assert(data[0] == 0xAABBCCDD);
20282028
-------------
20292029
)
20302030

20312031
$(P This requires the length of the hex string to be a multiple of the array element's size in bytes.)
20322032
$(SPEC_RUNNABLE_EXAMPLE_FAIL
20332033
-------------
2034-
auto e = cast(immutable ushort[]) x"AA BB CC";
2034+
static e = cast(immutable ushort[]) x"AA BB CC";
20352035
// Error, length of 3 bytes is not a multiple of 2, the size of a `ushort`
20362036
-------------
20372037
)
20382038

20392039
$(P When a hex string literal gets constant folded, the result is no longer considered a hex string literal)
20402040
$(SPEC_RUNNABLE_EXAMPLE_FAIL
20412041
-------------
2042-
immutable byte[] b = x"AA" ~ "G"; // Error: cannot convert `string` to `immutable byte[]`
2042+
static immutable byte[] b = x"AA" ~ "G"; // Error: cannot convert `string` to `immutable byte[]`
20432043
-------------
20442044
)
20452045

0 commit comments

Comments
 (0)