Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix removeOne for internal set #4482

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open

Fix removeOne for internal set #4482

wants to merge 1 commit into from

Conversation

Guttz
Copy link

@Guttz Guttz commented Dec 7, 2023

In the changed line, 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.Startproperly. 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)
}

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 <gustavopguto@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant