Skip to content

🐛 fix(mq-lang): improve NotDefined error token handling in eval.rs#1289

Merged
harehare merged 1 commit intomainfrom
fix/eval-token-error
Feb 17, 2026
Merged

🐛 fix(mq-lang): improve NotDefined error token handling in eval.rs#1289
harehare merged 1 commit intomainfrom
fix/eval-token-error

Conversation

@harehare
Copy link
Copy Markdown
Owner

  • Use func_name.token if available, fallback to get_token for better error reporting
  • Also improve token handling for module_path in NotDefined error

- Use func_name.token if available, fallback to get_token for better error reporting
- Also improve token handling for module_path in NotDefined error
Copilot AI review requested due to automatic review settings February 17, 2026 12:30
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Improves runtime diagnostics in mq-lang by attaching more accurate source tokens to RuntimeError::NotDefined when evaluating qualified module access, so error spans better match the user’s code.

Changes:

  • Prefer func_name.token (when present) over token_id for NotDefined errors in qualified module function calls.
  • Improve NotDefined token selection for non-module values by using the last module_path segment’s token/name when available.

.token
.as_ref()
.cloned()
.unwrap_or(get_token(Shared::clone(&self.token_arena), token_id));
Copy link

Copilot AI Feb 17, 2026

Choose a reason for hiding this comment

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

unwrap_or(get_token(...)) eagerly calls get_token even when func_name.token is Some, which defeats the purpose of preferring the provided token and does unnecessary arena cloning/indexing. Use unwrap_or_else(|| get_token(...)) so the fallback token is only fetched when needed.

Suggested change
.unwrap_or(get_token(Shared::clone(&self.token_arena), token_id));
.unwrap_or_else(|| get_token(Shared::clone(&self.token_arena), token_id));

Copilot uses AI. Check for mistakes.
.last()
.map(|m| (m.token.clone(), m.name.to_string()))
.unwrap_or_default();
let token = token.unwrap_or(get_token(Shared::clone(&self.token_arena), token_id));
Copy link

Copilot AI Feb 17, 2026

Choose a reason for hiding this comment

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

token.unwrap_or(get_token(...)) eagerly evaluates the fallback get_token(...) even when token is already Some. Prefer unwrap_or_else(|| get_token(...)) to avoid unnecessary arena cloning/indexing when the module path already carries a token.

Suggested change
let token = token.unwrap_or(get_token(Shared::clone(&self.token_arena), token_id));
let token =
token.unwrap_or_else(|| get_token(Shared::clone(&self.token_arena), token_id));

Copilot uses AI. Check for mistakes.
.as_ref()
.cloned()
.unwrap_or(get_token(Shared::clone(&self.token_arena), token_id));
Err(RuntimeError::NotDefined((*token).clone(), func_name.name.to_string()).into())
Copy link

Copilot AI Feb 17, 2026

Choose a reason for hiding this comment

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

This change alters which token is attached to RuntimeError::NotDefined for qualified module calls; there currently don't appear to be integration tests covering import ... | module::missing() / module::missing_ident cases. Add a regression test asserting the diagnostic points at the missing member token (and module path token where applicable) so future refactors don’t regress error location quality.

Copilot generated this review using guidance from repository custom instructions.
@codspeed-hq
Copy link
Copy Markdown

codspeed-hq bot commented Feb 17, 2026

Merging this PR will not alter performance

✅ 29 untouched benchmarks


Comparing fix/eval-token-error (d32fa86) with main (d799ed9)1

Open in CodSpeed

Footnotes

  1. No successful run was found on main (fcb1b2e) during the generation of this report, so d799ed9 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

@harehare harehare merged commit f34933f into main Feb 17, 2026
13 checks passed
@harehare harehare deleted the fix/eval-token-error branch February 17, 2026 12:39
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.

2 participants