Files
2026-10-17 21:57:03 +08:00

44 lines
1.4 KiB
Plaintext

import testcheck
import stdlib
import memhub
from conflict_node import Value
# G7: global variable 'Value' collides with class 'Value'
# Variable registration overrides the struct symbol, so struct body setup is skipped.
Value: rawptr = None
def test_value_struct_fields():
"""Verify the Value struct has 6 fields (Next + 5 own)."""
testcheck.section("Value struct field access (6 fields expected)")
arena: bytes = stdlib.malloc(4096)
if arena is None:
testcheck.check(False, "malloc arena", "FAIL")
return
pool: memhub.MemBuddy* = memhub.MemBuddy(arena, 4096)
node: Value* = pool.alloc(48)
if node is None:
testcheck.check(False, "alloc Value", "FAIL")
return
# Field 0: Next (inherited from GSListNode)
node.Next = None
# Fields 1-5: own fields
node.Ty = None
node.Name = None
node.IsConst = 1
node.IntVal = 42
node.FloatVal = 3.14
# Read back and verify
v: int = int(node.IntVal)
testcheck.check(v == 42, "Value.IntVal = 42", "expect 42")
f: double = node.FloatVal
testcheck.check(f > 3.0 and f < 4.0, "Value.FloatVal = 3.14", "expect ~3.14")
c: int = node.IsConst
testcheck.check(c == 1, "Value.IsConst = 1", "expect 1")
def main() -> int:
testcheck.begin("G7: Minimal repro - class name 'Value' conflicts with variable")
test_value_struct_fields()
return testcheck.end()