From 2c967dd24e63b388479c71f2648418c14f7b94b7 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Sun, 19 Nov 2023 14:50:40 +0900 Subject: [PATCH] internal/shader: bug fix: variables in an index should be marked as used Closes #2848 --- internal/shader/expr.go | 2 +- internal/shader/syntax_test.go | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/internal/shader/expr.go b/internal/shader/expr.go index abfebae85c39..8b4a0ffba59a 100644 --- a/internal/shader/expr.go +++ b/internal/shader/expr.go @@ -913,7 +913,7 @@ func (cs *compileState) parseExpr(block *block, fname string, expr ast.Expr, mar var stmts []shaderir.Stmt // Parse the index first - exprs, _, ss, ok := cs.parseExpr(block, fname, e.Index, markLocalVariableUsed) + exprs, _, ss, ok := cs.parseExpr(block, fname, e.Index, true) if !ok { return nil, nil, nil, false } diff --git a/internal/shader/syntax_test.go b/internal/shader/syntax_test.go index e57dab97e998..fae66988031d 100644 --- a/internal/shader/syntax_test.go +++ b/internal/shader/syntax_test.go @@ -514,6 +514,21 @@ func Fragment(position vec4, texCoord vec2, color vec4) vec4 { `)); err == nil { t.Errorf("error must be non-nil but was nil") } + + // Issue #2848 + if _, err := compileToIR([]byte(`package main + +func Fragment(dstPos vec4, srcPos vec2, color vec4) vec4 { + var floats [4]float + for i := 0; i < 3; i++ { + j := i + 1 + floats[j] = float(i) + } + return vec4(floats[0], floats[1], floats[2], floats[3]) +} +`)); err != nil { + t.Error(err) + } } func TestSyntaxBlankLhs(t *testing.T) {