Skip to content

Add class_evaluate for user-defined constant resolution#44

Merged
maedi merged 3 commits intolow-rb:mainfrom
obsidiannnn:fix/class-evaluate-user-defined-constants
May 5, 2026
Merged

Add class_evaluate for user-defined constant resolution#44
maedi merged 3 commits intolow-rb:mainfrom
obsidiannnn:fix/class-evaluate-user-defined-constants

Conversation

@obsidiannnn
Copy link
Copy Markdown
Contributor

@obsidiannnn obsidiannnn commented May 1, 2026

Currently, evaluation happens in the Evaluator’s binding, which prevents proper resolution of user-defined constants (e.g., CustomClass). This PR addresses that limitation.

Changes

  • Added class_evaluate method to evaluate expressions in the class context
  • Threaded class_binding through:
    • evaluate
    • evaluate_param_proxy_expressions
    • class_evaluate
  • When class_binding is present:
    • Uses class_evaluate for correct constant resolution
  • When class_binding is nil:
    • Falls back to instance_evaluate
    • Preserves existing refinements-based behavior for LowType built-in types

Impact

  • Enables correct resolution of user-defined constants
  • Maintains backward compatibility with existing evaluation logic

closes #40

using LowType::Syntax

def instance_evaluate(proxy:)
# Not a security risk because the code comes from a trusted source; the file that included lowtype.
Copy link
Copy Markdown
Member

@maedi maedi May 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like to keep this comment; developers are security conscious people and need to know I almost know what I'm doing. It can be put above the class definition line if it should now be a global message due to the multiple evals in the code now. Or go above each eval

@maedi
Copy link
Copy Markdown
Member

maedi commented May 3, 2026

Can you please add a spec that tests one simple use-case that this PR fixes? A custom class?

@maedi maedi merged commit ad35fc2 into low-rb:main May 5, 2026
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.

Evaluate constants in their original binding

2 participants