You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix: StringIndexOutOfBoundsException in presentation compiler's hasColon method (#23498)
This PR fixes a `StringIndexOutOfBoundsException` that could occur in
the presentation compiler when checking for colons in override
completions.
## Problem
The `dotty.tools.pc.completions.OverrideCompletions.hasColon` method was
accessing characters at specific indices without first verifying that
the indices were within the text bounds. This could cause crashes when
the span end positions were at or beyond the text length.
## Solution
Added bounds checking before accessing characters:
- For `TypeDef` cases: verify `td.rhs.span.end < text.length` before
`text.charAt(td.rhs.span.end)`
- For `Template` parent cases: filter to ensure `text.length > idx`
before `text.charAt(idx)`
## Testing
The existing test suite passes, and a new test case `no-new-line` was
added to cover the edge case.
[resolvesscalameta/metals#7575](scalameta/metals#7575)
0 commit comments