support shorthand enums in value-if
This commit is contained in:
@@ -10812,6 +10812,33 @@ main func() void {
|
||||
testing.expect_value(t, module.statements[module.functions[0].body[1]].kind, ast.Stmt_Kind.If)
|
||||
}
|
||||
|
||||
@(test)
|
||||
braceless_value_if_infers_shorthand_enum_from_use :: proc(t: ^testing.T) {
|
||||
directory := "/tmp/brolang-test-value-if-enum"
|
||||
main_path := "/tmp/brolang-test-value-if-enum/main.bro"
|
||||
output := "/tmp/brolang-test-value-if-enum-output"
|
||||
text := `Kind :: enum { first, second }
|
||||
Box :: struct { kind Kind }
|
||||
choose func(first bool) Kind {
|
||||
kind :: if (first) .first else .second
|
||||
return Box{kind = kind}.kind
|
||||
}
|
||||
main func() i32 {
|
||||
if (choose(true) != .first) return 1
|
||||
if (choose(false) != .second) return 2
|
||||
return 0
|
||||
}
|
||||
`
|
||||
_ = os2.remove_all(directory)
|
||||
defer _ = os2.remove_all(directory)
|
||||
defer _ = os.remove(output)
|
||||
testing.expect(t, os.make_directory(directory) == nil)
|
||||
testing.expect(t, os.write_entire_file(main_path, transmute([]byte)text))
|
||||
testing.expect_value(t, compiler_core.compile_package(directory, output), 0)
|
||||
state := run_executable(output)
|
||||
testing.expect_value(t, state.exit_code, 0)
|
||||
}
|
||||
|
||||
@(test)
|
||||
parser_accepts_braceless_while_bodies :: proc(t: ^testing.T) {
|
||||
text := `ready func() bool { return false }
|
||||
|
||||
Reference in New Issue
Block a user