Skip to content

Add constant type inference support#102

Merged
dak2 merged 1 commit into
mainfrom
feature/v020-constants
Mar 28, 2026
Merged

Add constant type inference support#102
dak2 merged 1 commit into
mainfrom
feature/v020-constants

Conversation

@dak2

@dak2 dak2 commented Mar 28, 2026

Copy link
Copy Markdown
Owner

Motivation

MethodRay did not track user-defined constants, so type errors on constant references (e.g., MAX.upcase where MAX = 100) were silently missed.

Changes

  • Add install_constant_write / install_constant_read in variables.rs with namespace-aware lookup (current scope → parent scopes → top-level)
  • Add constants HashMap to GlobalEnv for qualified constant name → VertexId mapping
  • Add ConstantWrite variant to NeedsChildKind and dispatch ConstantWriteNode
  • Extend ConstantReadNode dispatch to check constant table before falling back to Singleton type
  • Remove pass-through finish_ivar_write / finish_local_var_write wrappers, call install_* directly

Checked

  • cargo test --lib — 52 tests pass

🤖 Generated with Claude Code

@dak2 dak2 changed the title Add constant write/read support (CONST = value) Add constant write/read support Mar 28, 2026
@dak2 dak2 changed the title Add constant write/read support Add constant type infer support Mar 28, 2026
@dak2 dak2 force-pushed the feature/v020-constants branch from 3faec5a to d3a2018 Compare March 28, 2026 02:41
@dak2 dak2 changed the title Add constant type infer support Add constant type inference support Mar 28, 2026
@dak2 dak2 force-pushed the feature/v020-constants branch 3 times, most recently from bd734e5 to ca7e32c Compare March 28, 2026 03:02
MethodRay did not track user-defined constants,
so type errors on constant references (e.g.,
`MAX.upcase` where `MAX = 100`) were silently missed.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@dak2 dak2 force-pushed the feature/v020-constants branch from ca7e32c to 18acef4 Compare March 28, 2026 03:13
@dak2 dak2 merged commit 7f586b0 into main Mar 28, 2026
4 checks passed
@dak2 dak2 deleted the feature/v020-constants branch March 28, 2026 03:17
@dak2 dak2 added this to the v0.2.0 milestone Mar 28, 2026
@dak2 dak2 mentioned this pull request Apr 5, 2026
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant