Skip to content

Issue #543 : string.match returns nil when there is no match - #544

Open
eldologuzzo wants to merge 1 commit into
yuin:masterfrom
eldologuzzo:fix-string-match-nil
Open

eldologuzzo wants to merge 1 commit into
yuin:masterfrom
eldologuzzo:fix-string-match-nil

Conversation

@eldologuzzo

Copy link
Copy Markdown

Fixes #543 .

Changes proposed in this pull request:

  • strMatch pushed LNil when there is no match but returned 0, so string.match returned no value instead of nil (Lua 5.1 returns nil). Code such as tonumber(s:match("(%d+)")) failed with "value expected".
  • It now returns 1.
  • Test in _glua-tests/strings.lua: fails on current master and passes with this change. go test passes.

🤖 Generated with Claude Code

strMatch pushed LNil but returned 0, so no value reached the caller and
tonumber(s:match(...)) failed with "value expected".

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Copilot AI balanced review requested due to automatic review settings October 7, 2026 21:09

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Approval recommended

The focused implementation matches Lua 5.1 semantics and is adequately covered by regression tests.

0 open findings

What changed in this PR

Fixes string.match to return one explicit nil result when no match is found, matching Lua 5.1 behavior.

Changes:

  • Returns the pushed LNil value from strMatch.
  • Adds regression coverage for result count and tonumber(nil) behavior.
File Description
stringlib.go Corrects the no-match return count.
_glua-tests/​strings.lua Adds regression assertions for issue #543.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

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.

string.match returns no value instead of nil when there is no match

2 participants