Repository navigation
Fix IllegalStateException when typing an unterminated string in Go - #9660
Conversation
There was a problem hiding this comment.
Copilot review overview
🟢 Approval recommended
The shared lexer fix is consistent with existing mappings and is covered by focused regression tests.
Review effort: Balanced
Findings: None
What changed in this PR
Fixes unterminated Go strings causing lexer failures by tokenizing pending input at EOF.
Changes:
- Maps EOF with pending characters through each lexer’s token mapping.
- Handles TOML EOF as an error token.
- Adds Go lexer regression tests and JUnit support.
| File | Description |
|---|---|
AbstractAntlrLexerBridge.java |
Handles pending input at EOF. |
TomlLexer.java |
Maps pending EOF input to ERROR. |
GoLangLexerTest.java |
Adds lexer regression coverage. |
project.xml |
Adds JUnit 4 test dependency. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
|
"Secret" lock and unlock trick to pick up labels. 😄 |
|
@mbien looks a good thing to get in to NB32. Is it me, or are we not running |
I think the module didn't have any tests -> must be still added to the main.yaml edit: also please squash to a commit you want to see in the repo |
|
Ah, yes, missed that this had no tests before this PR. OK, @emilianbold can you add in to If this misses today's freeze cutoff I'd be inclined to re-target to delivery to get this into RC2. |
8c84229 to
ed92805
Compare
|
Added cc @neilcsmith-net @mbien — regarding the freeze cutoff / RC2: should this be re-targeted to |
mbien
left a comment
There was a problem hiding this comment.
its fine. you squashed it in time :)
…pache#9654) Typing a double quote as the last characters of a Go document made the lexer infrastructure throw: IllegalStateException: Lexer ...GoLangLexer returned null token but lexerInput.readLength()=6 Root cause: an unterminated literal at the end of the text makes the ANTLR lexer throw LexerNoViableAltException, after which it emits an end-of-input token while characters are still pending on the LexerInput. AbstractAntlrLexerBridge.nextToken() then returned null, but the consumed characters still needed a token. Fix it once in AbstractAntlrLexerBridge: when the ANTLR lexer reports end of input with pending input, delegate to mapToken() so the pending characters receive a token (implementations map EOF to an error-ish token in their default branch). A true end of input (readLength()==0) still returns null as before. Also fix TomlLexer.mapToken(), the only override of the nine ANTLR-backed languages that explicitly returned null for EOF, so it returns an ERROR token instead. Adds GoLangLexerTest as a regression test covering the issue text, unterminated rune and raw string literals, and that well formed text stays unaffected. Also add the languages.go test job to the CI workflow (.github/workflows/main.yml), next to the other languages.* modules; the module had no entry there because it had no tests before this PR. Assisted-by: mimo-v2.6-flash-free Assisted-by: DeepSeek-V4-Flash-IQ2XXS-w2Q2K-AProjQ8-SExpQ8-OutQ8-chat-v2-imatrix-0731 (on ds4j) Assisted-by: GLM-5.3
ed92805 to
7ddb1bc
Compare
|
OK, I guess you have to merge it no? |
|
i can merge it. thought your account has repo access? the rule about not merging would be if it targets delivery. In that case release managers decide since it could cause conflicts etc. delivery didn't branch yet. |
Thank you. I haven't committed here in a while so I didn't want to overstep. |
|
ah. no worries. thanks for fixing the go issue and welcome back :) |
Closes #9654
In AbstractAntlrLexerBridge: when the ANTLR lexer reports end of input with pending input, delegate to mapToken() so the pending characters receive a token (implementations map EOF to an error-ish token in their default branch). A true end of input (readLength()==0) still returns null as before.
Also adds the module's first tests (GoLangLexerTest, covering the issue text plus unterminated rune and raw string literals) and lists ide/languages.go in the CI workflow (.github/workflows/main.yml) next to the other languages.* modules so they run on CI.
Assisted-by: mimo-v2.6-flash-free
Assisted-by: DeepSeek-V4-Flash-IQ2XXS-w2Q2K-AProjQ8-SExpQ8-OutQ8-chat-v2-imatrix-0731 (on ds4j)
Assisted-by: GLM-5.3 (CI workflow entry, squash)
^Add meaningful description above
Click to collapse/expand PR instructions
By opening a pull request you confirm that, unless explicitly stated otherwise, the changes -
LLMs, Commit messages and PR description:
git log) that all commits have a valid name and email address for you in the Author field.Assisted-by: MODEL_NAME MODEL_VERSIONline appended to the commit message.Assisted-byline from above)If you're a first time contributor, see the Contributing guidelines for more information.
If you're a committer, please label the PR before pressing "Create pull request" so that the right test jobs can run.
PR approval and merge checklist:
If this PR targets the delivery branch: don't merge. (full wiki article)