Commit 01447df
authored
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.
[resolves
scalameta/metals#7575](scalameta/metals#7575)1 parent 97896fa commit 01447df
File tree
2 files changed
+48
-28
lines changed- presentation-compiler
- src/main/dotty/tools/pc/completions
- test/dotty/tools/pc/tests/edit
2 files changed
+48
-28
lines changedLines changed: 2 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
511 | 511 | | |
512 | 512 | | |
513 | 513 | | |
514 | | - | |
| 514 | + | |
515 | 515 | | |
516 | 516 | | |
517 | | - | |
| 517 | + | |
518 | 518 | | |
519 | 519 | | |
520 | 520 | | |
| |||
Lines changed: 46 additions & 26 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
75 | 75 | | |
76 | 76 | | |
77 | 77 | | |
78 | | - | |
| 78 | + | |
79 | 79 | | |
80 | 80 | | |
81 | | - | |
82 | | - | |
83 | | - | |
84 | | - | |
85 | | - | |
86 | | - | |
87 | | - | |
88 | | - | |
89 | | - | |
90 | | - | |
91 | | - | |
92 | | - | |
93 | | - | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
94 | 86 | | |
95 | 87 | | |
96 | | - | |
97 | | - | |
98 | | - | |
99 | | - | |
100 | | - | |
101 | | - | |
102 | | - | |
| 88 | + | |
| 89 | + | |
103 | 90 | | |
104 | | - | |
| 91 | + | |
105 | 92 | | |
106 | | - | |
| 93 | + | |
107 | 94 | | |
108 | | - | |
109 | | - | |
110 | | - | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
111 | 131 | | |
112 | 132 | | |
113 | 133 | | |
| |||
0 commit comments