fix code() failing with "line number not found in file stdio" on pasted input#4358
Draft
d-torrance wants to merge 1 commit into
Draft
fix code() failing with "line number not found in file stdio" on pasted input#4358d-torrance wants to merge 1 commit into
d-torrance wants to merge 1 commit into
Conversation
…ed input
readline 8+ enables bracketed paste mode by default. When the user
pastes multiple lines at once, readline() can return a single string
containing embedded newlines (e.g. "expr1\nexpr2") rather than one
line per readline() call.
The old code called add_history() on the entire returned string, so
the whole paste was stored as one history entry. Meanwhile M2's
parser incremented lineNumber for every '\n' it saw, creating a
mismatch: after a two-line paste the session line counter was 2 but
only one new history entry existed.
code.m2 maps M2 line numbers to history entries via
getHistory(lineNumber + historyOffset)
so getHistory(2 + historyOffset) would call history_get() with an
out-of-range index, return NULL, and ultimately produce:
error: line number 1 not found in file stdio
Fix: instead of a single add_history(p), split p at each embedded '\n'
and add each segment as its own history entry (save/restore the '\n'
in-place). For single-line input (the common case) this is identical
to the previous behaviour.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Member
|
I don't think Claude identified the correct solution. We don't want to split user's input into several lines. It is a feature that if I paste multiple lines, then want to redo the same thing, I can go up until I get to the full multiline input and enter it again. I'm not even sure Claude identified the correct problem. e.g. this works fine: i1 : g = () -> (
L = {};
for i to 4000 do (
L = append(L, i)
)
)
o1 = g
o1 : FunctionClosure
i2 : code g
o2 = stdio:1:4-6:5: --source code:
g = () -> (
L = {};
for i to 4000 do (
L = append(L, i)
)
)Which indicates that lines 1 through 6 were correctly retrieved from history. |
Contributor
|
I'm a little confused what this has to do with |
Member
Author
|
They do use readline a bit -- in particular for grabbing the code of things defined in stdio |
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.
readline 8+ enables bracketed paste mode by default. When the user pastes multiple lines at once, readline() can return a single string containing embedded newlines (e.g. "expr1\nexpr2") rather than one line per readline() call.
The old code called add_history() on the entire returned string, so the whole paste was stored as one history entry. Meanwhile M2's parser incremented lineNumber for every '\n' it saw, creating a mismatch: after a two-line paste the session line counter was 2 but only one new history entry existed.
code.m2 maps M2 line numbers to history entries via
getHistory(lineNumber + historyOffset)
so getHistory(2 + historyOffset) would call history_get() with an out-of-range index, return NULL, and ultimately produce:
Fix: instead of a single add_history(p), split p at each embedded '\n' and add each segment as its own history entry (save/restore the '\n' in-place). For single-line input (the common case) this is identical to the previous behaviour.
Fixes: #4356
AI Disclosure
This was 100% Claude Code