Skip to content

Commit

Permalink
fixed typed nil in if
Browse files Browse the repository at this point in the history
  • Loading branch information
generikvault committed Jun 3, 2021
1 parent 02e0f36 commit 418b0b6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
16 changes: 16 additions & 0 deletions gval_parameterized_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -608,6 +608,22 @@ func TestParameterized(t *testing.T) {
}{},
want: 99.,
},
{
name: "operator with typed nil 99",
expression: `ProjectID + 99`,
parameter: struct {
ProjectID *uint
}{},
want: "<nil>99",
},
{
name: "operator with typed nil if",
expression: `Flag ? 1 : 2`,
parameter: struct {
Flag *uint
}{},
want: 2.,
},
},
t,
)
Expand Down
2 changes: 1 addition & 1 deletion parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ func parseIf(c context.Context, p *Parser, e Evaluable) (Evaluable, error) {
if err != nil {
return nil, err
}
if x == false || x == nil {
if valX := reflect.ValueOf(x); x == nil || valX.IsZero() {
return b(c, v)
}
return a(c, v)
Expand Down

0 comments on commit 418b0b6

Please sign in to comment.