Skip to content

Commit

Permalink
Enforce new allocation for appends on cloned joins slice
Browse files Browse the repository at this point in the history
  • Loading branch information
Frantisek Haifler authored and doug-martin committed Apr 22, 2021
1 parent 71f3e01 commit 458000e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
2 changes: 1 addition & 1 deletion exp/select_clauses.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func (c *selectClauses) clone() *selectClauses {
selectColumns: c.selectColumns,
distinct: c.distinct,
from: c.from,
joins: c.joins,
joins: c.joins[0:len(c.joins):len(c.joins)],
where: c.where,
alias: c.alias,
groupBy: c.groupBy,
Expand Down
16 changes: 14 additions & 2 deletions exp/select_clauses_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,21 +160,33 @@ func (scs *selectClausesSuite) TestJoins() {
func (scs *selectClausesSuite) TestJoinsAppend() {
jc := NewConditionedJoinExpression(
LeftJoinType,
NewIdentifierExpression("", "test", ""),
NewIdentifierExpression("", "test1", ""),
nil,
)
jc2 := NewUnConditionedJoinExpression(
LeftJoinType,
NewIdentifierExpression("", "test", ""),
NewIdentifierExpression("", "test2", ""),
)
jc3 := NewUnConditionedJoinExpression(
InnerJoinType,
NewIdentifierExpression("", "test3", ""),
)
c := NewSelectClauses()
c2 := c.JoinsAppend(jc)
c3 := c2.JoinsAppend(jc2)

c4 := c3.JoinsAppend(jc2) // len(c4.joins) == 3, cap(c4.joins) == 4
// next two appends shouldn't affect one another
c5 := c4.JoinsAppend(jc2)
c6 := c4.JoinsAppend(jc3)

scs.Nil(c.Joins())

scs.Equal(JoinExpressions{jc}, c2.Joins())
scs.Equal(JoinExpressions{jc, jc2}, c3.Joins())
scs.Equal(JoinExpressions{jc, jc2, jc2}, c4.Joins())
scs.Equal(JoinExpressions{jc, jc2, jc2, jc2}, c5.Joins())
scs.Equal(JoinExpressions{jc, jc2, jc2, jc3}, c6.Joins())
}

func (scs *selectClausesSuite) TestWhere() {
Expand Down

0 comments on commit 458000e

Please sign in to comment.