Skip to content

Commit

Permalink
fix generated unary (#854)
Browse files Browse the repository at this point in the history
  • Loading branch information
brennanjl authored Jun 22, 2024
1 parent 2d85b4c commit 5ef667b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
4 changes: 3 additions & 1 deletion internal/engine/generate/plpgsql.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ func (s *sqlGenerator) VisitExpressionArithmetic(p0 *parse.ExpressionArithmetic)
func (s *sqlGenerator) VisitExpressionUnary(p0 *parse.ExpressionUnary) any {
str := strings.Builder{}
str.WriteString(string(p0.Operator))
str.WriteString(" ")
str.WriteString(p0.Expression.Accept(s).(string))
// cannot be typecasted
return str.String()
Expand Down Expand Up @@ -802,7 +803,7 @@ func (p *procedureGenerator) VisitProcedureStmtForLoop(p0 *parse.ProcedureStmtFo
s.WriteString(stmt.Accept(p).(string))
}

s.WriteString("END LOOP;\n")
s.WriteString(" END LOOP;\n")

return s.String()
}
Expand Down Expand Up @@ -855,6 +856,7 @@ func (p *procedureGenerator) VisitIfThen(p0 *parse.IfThen) any {
for _, stmt := range p0.Then {
s.WriteString(stmt.Accept(p).(string))
}
s.WriteString("\n")

return s.String()
}
Expand Down
8 changes: 8 additions & 0 deletions internal/engine/integration/procedure_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,14 @@ func Test_Procedures(t *testing.T) {
err: execution.ErrMutativeProcedure,
readOnly: true,
},
{
// this is a regression test for a previous bug
name: "unary",
procedure: `procedure unary() public view returns (bool) {
return !true;
}`,
outputs: [][]any{{false}},
},
}

for _, test := range tests {
Expand Down

0 comments on commit 5ef667b

Please sign in to comment.