From ebaa15f02dd0e5aa358ea2e527ae4557e40b4e9c Mon Sep 17 00:00:00 2001 From: zinc Date: Wed, 14 Oct 2026 09:33:03 +0000 Subject: constants inside structs, and typo suggestions for fields and static members const NAME = e; inside a struct body declares a compile-time constant named Struct.NAME, reached as Struct.NAME or by bare name in the struct's methods. A misspelled field or Struct.name member now ends its error with '; did you mean 'name'?' on the member word, which the language server turns into a quick fix. --- tests/programs/struct_const.zc | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 tests/programs/struct_const.zc (limited to 'tests/programs') diff --git a/tests/programs/struct_const.zc b/tests/programs/struct_const.zc new file mode 100644 index 0000000..59af8fd --- /dev/null +++ b/tests/programs/struct_const.zc @@ -0,0 +1,28 @@ +namespace; +include rt; + +struct Text { + const MAX = 24, MIN = 1; + const int WIDE = MAX * 2; + int len, tag; + static int top() { return MAX; } + static int span() { return MAX - MIN; } + int room() { return MAX - this.len; } + int total() { int[MIN + 2] a; a[2] = WIDE; return a[2] + this.tag; } +} + +const MAX = 99; + +int main() { + Text t; + t.len = 5; t.tag = 7; + rt.put_n(Text.MAX); rt.put_c(32); + rt.put_n(Text.MIN + Text.WIDE); rt.put_c(32); + rt.put_n(Text.top()); rt.put_c(32); + rt.put_n(Text.span()); rt.put_c(32); + rt.put_n(t.room()); rt.put_c(32); + rt.put_n(t.total()); rt.put_c(32); + rt.put_n(t.len + t.tag); rt.put_c(32); + rt.put_n(MAX); rt.put_c(10); + return 0; +} -- cgit v1.2.3