Add identifier not found error handling to evaluator - #389
Open
DeveloperC286 wants to merge 1 commit into
Open
Conversation
Environment::get returned Object::Null when a name was not bound anywhere in the environment chain, so a typo silently produced a null value. The mistake then surfaced further downstream as a confusing type mismatch, pointing at the operator rather than at the undefined name. Environment::get now returns Option<Object>, and identifier evaluation moves into its own module which bails with "Identifier not found: <name>." when the lookup misses. identifier_expression_case_8 enshrined the old behaviour, evaluating "let is_directory = false;\nis_file" and asserting Ok(Null). It now references the identifier it binds, and the undefined-identifier code it used to cover moves to the new identifier_not_found evaluation error suite alongside nine other cases. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Htq6Br9uauDWFGr9zPxTyc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR implements proper error handling for undefined identifiers in the evaluator. Previously, accessing an undefined identifier would return
Null, but now it correctly raises an "Identifier not found" error.Key Changes
Environment.get()method to returnOption<Object>instead ofObject, allowing distinction between a variable that exists with aNullvalue and a variable that doesn't exist at allevaluate_identifier_expression()method that returns an error when an identifier is not found in the environmentImplementation Details
Environment.get()method now properly propagatesNonethrough the environment chain when a variable is not found, rather than defaulting toNullFalseinstead ofNull)https://claude.ai/code/session_01Htq6Br9uauDWFGr9zPxTyc