Fix off-by-one in source regions emitted to JSON and Debug.todo#2359
Merged
Conversation
In 0.19.2 `Position` became a packed `Word64#`, and its own comment notes
that "The initial value is (0,0) so conversion is needed to get 'editor
coordinates' which start at (1,1)".
`Reporting.Render.Code` does that conversion, which is why the terminal
error report is still correct. The two places that emit machine-readable
coordinates call `toRowCol` raw and do not convert:
* `Reporting.Error.encodeRegion` -- elm make --report=json
* `Generate.JavaScript.Expression.regionToJsExpr` -- Debug.todo / todoCase
So `--report=json`, which editors and elm-language-server consume, and the
runtime `TODO in module `M` on line N` message are both one line and one
column too low. A `Debug.todo` on line 17, column 5 emits
`{start: {line: 16, column: 4}, ...}` and crashes with "on line 16".
Add a `toEditorRowCol` helper and use it at both emit sites. A uniform +1
on row and column reproduces the 0.19.1 output byte for byte.
Fixes elm#2358
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
Thanks for suggesting these code changes. To set expectations:
Finally, please be patient with the core team. They are trying their best with limited resources. |
This was referenced Jul 8, 2026
Member
|
Thank you! I like the approach of having a separate naming convention for "editor rows" and "editor columns". Sad I did not catch this in the pre-release, but there should be a 0.19.3 relatively soon. |
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.
Fixes #2358.
In 0.19.2
Reporting.Annotation.Positionbecame a packedWord64#, and its own comment states the new contract:Reporting.Render.Codeperforms that conversion (show (row + 1)), which is why the terminal error report is still correct. The two places that emit machine-readable coordinates callA.toRowColraw and never convert:Reporting.Error.encodeRegion— used byelm make --report=json, which editors andelm-language-serverconsumeGenerate.JavaScript.Expression.regionToJsExpr— used forDebug.todo/Debug.todoCaseSo every JSON diagnostic is one line up and one column left, and a
Debug.todoon line 17 crashes withTODO in module `Main` on line 16.The change
Add a
toEditorRowColhelper next totoRowColand use it at the two emit sites.Reporting.Render.CodeusestoRow/toColdirectly and already does its own conversion, so it is untouched.Note: after this change
toRowColhas no remaining callers — both of its consumers wanted editor coordinates. MakingtoRowColitself 1-based would be a smaller diff; I kept a separately named function so the (0,0)-based accessor stays available and the conversion is explicit at the point of use. Happy to switch to whichever you prefer.Verification
Built with GHC 9.8.4 (
cabal build exe:elm, so under the package's-Wall -Werror): 137/137 modules, links cleanly.SSCCE from #2358 —
Debug.todoon line 17, column 5; type error on line 6, columns 5–17:Debug.todoregion--report=jsonregion(17,5)–(17,15)on line 17(6,5)–(6,17)(16,4)–(16,14)on line 16(5,4)–(5,16)(17,5)–(17,15)on line 17(6,5)–(6,17)The patched compiler matches 0.19.1 exactly.
Also checked:
6| "not an int"with the caret correctly aligned, i.e. not double-incremented.Debug.todoregions emitted into the bundle become identical to the 0.19.1 output (Δline = Δcolumn = 0 for every one), where before the patch every one was off by exactly(-1, -1).