comptime expandable match statements

This commit is contained in:
2026-07-17 14:29:50 +02:00
parent 1f25e6cd1d
commit 97f1c06057
22 changed files with 120821 additions and 119318 deletions
+107 -2
View File
@@ -279,7 +279,7 @@ choose func() i32 {
(identifier)))))))
==================
Tuples and inline for
Tuples and expand for
==================
Pair :: struct { i32, []u8 }
@@ -289,7 +289,7 @@ main func() void {
singleton :: {1,}
empty :: {}
_ = pair.0
inline for singleton |value| {
expand for singleton |value| {
_ = value
}
}
@@ -365,3 +365,108 @@ main func() void {
(sink))
(expression
(identifier))))))))))
==================
Expanded match arms
==================
Kind :: enum { one, two }
Value :: union(enum) { number i32, empty void }
test func(kind Kind, value Value) void {
match kind {
.one: {}
expand |tag|: _ = tag
}
match value {
expand |@payload, tag|: {
_ = payload
_ = tag
}
}
}
---
(source_file
(type_declaration
(identifier)
(enum_type
(enum_body
(enum_member
(identifier))
(enum_member
(identifier)))))
(type_declaration
(identifier)
(union_type
(record_body
(record_field
(identifier)
(type
(builtin_type)))
(record_field
(identifier)
(type
(builtin_type))))))
(function_declaration
(identifier)
(parameter_list
(parameter
(identifier)
(type
(named_type
(qualified_identifier
(identifier)))))
(parameter
(identifier)
(type
(named_type
(qualified_identifier
(identifier))))))
(type
(builtin_type))
(block
(statement
(match_statement
(expression
(identifier))
(match_arm
(expression
(enum_literal
(identifier)))
(statement
(expression_statement
(expression
(tuple_literal)))))
(match_arm
(expand_match_capture
(identifier))
(statement
(assignment_statement
(expression
(sink))
(expression
(identifier)))))))
(statement
(match_statement
(expression
(identifier))
(match_arm
(expand_match_capture
(identifier)
(identifier))
(statement
(block
(statement
(assignment_statement
(expression
(sink))
(expression
(identifier))))
(statement
(assignment_statement
(expression
(sink))
(expression
(identifier))))))))))))