diff --git a/internal/shader/expr.go b/internal/shader/expr.go index 6373e251d..a7007b008 100644 --- a/internal/shader/expr.go +++ b/internal/shader/expr.go @@ -369,14 +369,6 @@ func (cs *compileState) parseExpr(block *block, expr ast.Expr) ([]shaderir.Expr, return exprs, f.ir.OutParams, stmts, true case *ast.Ident: - if e.Name == "true" || e.Name == "false" { - return []shaderir.Expr{ - { - Type: shaderir.NumberExpr, - Const: gconstant.MakeBool(e.Name == "true"), - }, - }, []shaderir.Type{{Main: shaderir.Bool}}, nil, true - } if e.Name == "_" { return []shaderir.Expr{ { @@ -425,6 +417,14 @@ func (cs *compileState) parseExpr(block *block, expr ast.Expr) ([]shaderir.Expr, }, }, nil, nil, true } + if e.Name == "true" || e.Name == "false" { + return []shaderir.Expr{ + { + Type: shaderir.NumberExpr, + Const: gconstant.MakeBool(e.Name == "true"), + }, + }, []shaderir.Type{{Main: shaderir.Bool}}, nil, true + } cs.addError(e.Pos(), fmt.Sprintf("unexpected identifier: %s", e.Name)) case *ast.ParenExpr: diff --git a/shader_test.go b/shader_test.go index ed0ea0497..d2f74d0e9 100644 --- a/shader_test.go +++ b/shader_test.go @@ -506,3 +506,15 @@ func Fragment(position vec4, texCoord vec2, color vec4) vec4 { t.Errorf("error must be non-nil but was nil") } } + +func TestShaderBoolLiteral(t *testing.T) { + if _, err := NewShader([]byte(`package main + +func Fragment(position vec4, texCoord vec2, color vec4) vec4 { + true := vec4(0) + return true +} +`)); err != nil { + t.Errorf("error must be nil but was non-nil") + } +}