Skip to content

Commit

Permalink
Fix removeOne for internal set
Browse files Browse the repository at this point in the history
Here, in go, if we assign a slice position to a variable, we'll have a copy.

ki.Start = v + 1, on line 218, was just modifying a copy, which is not what was intended to be done here.

If we get the reference as done in the change, we'll modify `ki.Start`properly. Another option would be to reasign the copy to the array position. Either way, this should be fixed.

Simple test which would fail:

func (suite *IIntervalSetTestSuite) TestRemoveOne() {
	i := NewIntervalSet()
	i.addInterval(antlr.NewInterval(5, 10))

	i.removeOne(7)

	suite.Len(i.intervals, 2)
	suite.Equal(5, i.intervals[0].Start)
	suite.Equal(7, i.intervals[0].Stop)
	suite.Equal(8, i.intervals[1].Start)
	suite.Equal(10, i.intervals[1].Stop)
}



Signed-off-by: Gustavo de Morais <[email protected]>
  • Loading branch information
gustavodemorais authored Dec 7, 2023
1 parent d25d421 commit 8bf2a29
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion runtime/Go/antlr/v4/interval_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ func (i *IntervalSet) removeRange(v Interval) {
func (i *IntervalSet) removeOne(v int) {
if i.intervals != nil {
for k := 0; k < len(i.intervals); k++ {
ki := i.intervals[k]
ki := &i.intervals[k]
// intervals i ordered
if v < ki.Start {
return
Expand Down

0 comments on commit 8bf2a29

Please sign in to comment.