From e543d4f107ca3e84dd5f6d53d4c58908557f2861 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Sun, 13 Sep 2020 20:38:51 +0900 Subject: [PATCH] shader: Bug fix: true/false should be available as a local variable --- internal/shader/expr.go | 16 ++++++++-------- shader_test.go | 12 ++++++++++++ 2 files changed, 20 insertions(+), 8 deletions(-) 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") + } +}