Skip to content

Commit

Permalink
internal/shader: bug fix: variables in an index should be marked as used
Browse files Browse the repository at this point in the history
Closes #2848
  • Loading branch information
hajimehoshi committed Nov 19, 2023
1 parent 96d58bb commit 2c967dd
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion internal/shader/expr.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
15 changes: 15 additions & 0 deletions internal/shader/syntax_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 2c967dd

Please sign in to comment.