This commit is contained in:
nub31
2026-03-10 17:53:42 +01:00
parent 6507624e90
commit 2ab20652f8
3 changed files with 10 additions and 6 deletions

View File

@@ -721,7 +721,7 @@ static inline string *string_from_cstr(char *cstr)
if (value != null) if (value != null)
writer.WriteLine($", .{enumVariantType.Variant} = {value} }};"); writer.WriteLine($", .{enumVariantType.Variant} = {value} }};");
else else
writer.WriteLine(" }};"); writer.WriteLine(" };");
return name; return name;
} }

View File

@@ -672,10 +672,10 @@ public class TypeChecker
throw BasicError($"Enum '{variantType.EnumType}' does not have a variant named '{variantType.Variant}'", expression.Type); throw BasicError($"Enum '{variantType.EnumType}' does not have a variant named '{variantType.Variant}'", expression.Type);
if (expression.Value == null && variant.Type is not null) if (expression.Value == null && variant.Type is not null)
throw BasicError($"Enum variant '{variantType.EnumType}' expects a value of type '{variant.Type}'", expression.Type); throw BasicError($"Enum variant '{variantType}' expects a value of type '{variant.Type}'", expression.Type);
if (expression.Value != null && variant.Type is null) if (expression.Value != null && variant.Type is null)
throw BasicError($"Enum variant '{variantType.EnumType}' does not expect any data", expression.Value); throw BasicError($"Enum variant '{variantType}' does not expect any data", expression.Value);
var value = expression.Value == null ? null : CheckExpression(expression.Value, variant.Type); var value = expression.Value == null ? null : CheckExpression(expression.Value, variant.Type);

View File

@@ -11,12 +11,16 @@ enum Message {
} }
func main(): i32 { func main(): i32 {
let messages: []Message = [new Message::Say("first"), new Message::Say("second")] let messages: []Message = [new Message::Say("first"), new Message::Quit]
for message in messages { for message in messages {
match message { match message {
Say msg core::println(msg) Say msg {
Quit {} core::println(msg)
}
Quit {
core::println("quit")
}
} }
} }