Skip to content

Commit

Permalink
Fixes #9332. Now checks that aPosition is within limits before access…
Browse files Browse the repository at this point in the history
…ing the sourceCode, preventing a SubscriptOutOfBounds
  • Loading branch information
mwillemb committed May 28, 2021
1 parent 013aaaa commit aeac411
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions src/AST-Core/RBProgramNode.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -216,13 +216,19 @@ RBProgramNode >> bestNodeForPosition: aPosition [
This heuristic introduces although an ambiguity when code is not nicely formatted:
self foo:|#bar => Here a user may want foo: or bar.
For now we decided to favor foo: to motivate people to indent code correctly "

| offset position |
offset := (aPosition = 1 or: [ (self methodNode sourceCode at: aPosition - 1) isSeparator ])
ifTrue: [ 0 ]
ifFalse: [ -1 ].

position := (aPosition + offset) min: self stop.
| offset position precededBySeparator |
precededBySeparator := (aPosition
between: 2
and: self methodNode sourceCode size + 1)
and: [
(self methodNode sourceCode at: aPosition - 1)
isSeparator ].
offset := (aPosition = 1 or: [ precededBySeparator ])
ifTrue: [ 0 ]
ifFalse: [ -1 ].

position := aPosition + offset min: self stop.

^ self bestNodeFor: (position to: position)
]
Expand Down

0 comments on commit aeac411

Please sign in to comment.