more comptime eval

This commit is contained in:
2026-07-03 15:54:28 +02:00
parent e00a4e929a
commit adf142736c
7 changed files with 2266 additions and 481 deletions
+37 -14
View File
@@ -2338,26 +2338,25 @@ main func() i32 {
}
@(test)
comptime_expression_diagnoses_unsupported_v1_evaluation :: proc(t: ^testing.T) {
text := `loop func() int {
comptime_expression_diagnoses_runtime_only_and_quota :: proc(t: ^testing.T) {
text := `native c_func() i32
spin func() i32 {
while true {
return 1
}
return 0
}
missing func() int {
missing func() i32 {
if true {
}
}
recurse func(value int) int {
return recurse(value)
}
GLOBAL :: 1
main func() void {
runtime i32 = 1
_ = $runtime
_ = $loop()
_ = $native()
_ = $&GLOBAL
_ = $spin()
_ = $missing()
_ = $recurse(1)
_ = ${
value :: 1
}
@@ -2375,13 +2374,27 @@ main func() void {
hir_module := checker.check(&ast_module, &diagnostics, &symbols)
defer hir.destroy_module(&hir_module)
found := 0
found_runtime := false
found_external := false
found_pointer := false
found_quota := false
found_missing := false
found_yield := false
for diagnostic in diagnostics.items {
if strings.contains(diagnostic.message, "expression cannot be evaluated at comptime") {
found += 1
}
message := diagnostic.message
found_runtime = found_runtime || strings.contains(message, "unresolved comptime value 'runtime'")
found_external = found_external || strings.contains(message, "runtime-only")
found_pointer = found_pointer || strings.contains(message, "pointers and slices are not supported")
found_quota = found_quota || strings.contains(message, "comptime evaluation exceeded the step quota")
found_missing = found_missing || strings.contains(message, "did not return a value")
found_yield = found_yield || strings.contains(message, "comptime block must yield a value")
}
testing.expect(t, found >= 5)
testing.expect(t, found_runtime)
testing.expect(t, found_external)
testing.expect(t, found_pointer)
testing.expect(t, found_quota)
testing.expect(t, found_missing)
testing.expect(t, found_yield)
}
@(test)
@@ -5774,6 +5787,16 @@ comptime_eval_compile_and_run :: proc(t: ^testing.T) {
testing.expect_value(t, state.exit_code, 0)
}
@(test)
comptime_v1_compile_and_run :: proc(t: ^testing.T) {
output := "/tmp/brolang-test-comptime-v1"
defer _ = os.remove(output)
status := compiler_core.compile_package("examples/programs/comptime_v1", output)
testing.expect_value(t, status, 0)
state := run_executable(output)
testing.expect_value(t, state.exit_code, 0)
}
@(test)
lazy_function_body_marks_import_as_used_without_resolving_it :: proc(t: ^testing.T) {
output := "/tmp/brolang-test-package-lazy-import"