fix #28990, improve top-level location info #30641
Merged
+139
−85
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.
This fixes #28990, plus the following issue:
Before:
After:
This works by (1) passing an initial filename and line number to lowering (so that locations set in a
:toplevel
expression can apply to the following expression), and (2) making the REPL use the same parsing function that files (andinclude_string
) use, which puts a line node before each expression.Base.parse_input_line
now wraps everything in a:toplevel
expression including a line node.The low-level parser entry points are simplified and renamed to parse-one, parse-all, and parse-file.
The
ex === ()
check inparse
I believe was dead code; it looks like something that was left out when we replaced()
withnothing
a long time ago. All parsing functions returnnothing
forparse("")
, so giving an error here would be breaking but we can consider whether we want to switch to that.Question 1: I believe the code in interpreter.c setting
jl_lineno
(which this PR removes)is not necessary, since we should now be able to get line numbers from the interpreter stack trace mechanism. Can anyone think of a reason we need that code?Question 2: I don't understand the need for the change to
repl_filename
. Without it, the filename for the first repl input isREPL[0]
if the input is very simple, e.g.error()
as in the example above. But if I insert even just a single space (within the same input cell) beforeerror()
, then you getREPL[1]
.