Commit f2785f69

f2785f692d3dMerged

Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 1 file · +1 added

Description

test: add regression test for class-scoped constant path reads

Issue #52 reported that class User; MAX = 20; end; puts User::MAX emitted User_MAX as an undeclared C identifier. The current codegen emits it as cst_User_MAX with a matching declaration, and the reproducer prints 20 cleanly. The fix landed earlier as part of the broader constant-resolution work (commits b9487db, d3171e3, 2cda5c7); this just nails down the original reproducer plus a few neighbouring shapes (top-level const, module const, nested class const) so they can't silently regress.

Closes #52

Co-Authored-By: Claude Opus 4.7 (1M context) [email protected]

Details

Commit
f2785f692d3d
Parent
a03517c7529d

test/class_constant_path_read.rbaddedView file

1+# Issue #52: reading a class-scoped constant from outside the class
2+# via `ClassName::CONST` used to emit `User_MAX_NAME_LENGTH` as an
3+# undeclared C identifier. Now it's emitted as `cst_User_MAX_NAME_LENGTH`
4+# with a matching declaration.
5+
6+class User
7+ MAX_NAME_LENGTH = 20
8+end
9+
10+puts User::MAX_NAME_LENGTH # 20
11+
12+# Mixed reads: class const, module const, top-level const all
13+# accessible via the same path forms.
14+TOP = 1
15+
16+module Site
17+ ROOT = 2
18+
19+ class Page
20+ LIMIT = 3
21+ end
22+end
23+
24+puts TOP # 1
25+puts Site::ROOT # 2
26+puts Site::Page::LIMIT # 3