diff --git a/internal/shader/stmt.go b/internal/shader/stmt.go index 2ac5e7bdb..943dfb36e 100644 --- a/internal/shader/stmt.go +++ b/internal/shader/stmt.go @@ -346,7 +346,7 @@ func (cs *compileState) parseStmt(block *block, fname string, stmt ast.Stmt, inP }) case *ast.IncDecStmt: - exprs, _, ss, ok := cs.parseExpr(block, stmt.X, false) + exprs, _, ss, ok := cs.parseExpr(block, stmt.X, true) if !ok { return nil, false } diff --git a/shader_test.go b/shader_test.go index c322db999..d58d43254 100644 --- a/shader_test.go +++ b/shader_test.go @@ -225,7 +225,7 @@ func Fragment(position vec4, texCoord vec2, color vec4) vec4 { return vec4(0) } `)); err != nil { - t.Errorf("error must be nil but non-nil: %v", err) + t.Error(err) } if _, err := NewShader([]byte(`package main @@ -236,7 +236,7 @@ func Fragment(position vec4, texCoord vec2, color vec4) vec4 { return vec4(0) } `)); err != nil { - t.Errorf("error must be nil but non-nil: %v", err) + t.Error(err) } } @@ -576,6 +576,8 @@ func Fragment(position vec4, texCoord vec2, color vec4) vec4 { t.Errorf("error must be non-nil but was nil") } + // Increment statement treats a variable 'used'. + // https://play.golang.org/p/2RuYMrSLjt3 if _, err := NewShader([]byte(`package main func Fragment(position vec4, texCoord vec2, color vec4) vec4 { @@ -583,8 +585,8 @@ func Fragment(position vec4, texCoord vec2, color vec4) vec4 { x++ return vec4(0) } -`)); err == nil { - t.Errorf("error must be non-nil but was nil") +`)); err != nil { + t.Error(err) } } @@ -630,6 +632,16 @@ func Fragment(position vec4, texCoord vec2, color vec4) vec4 { _ = x return vec4(0) } +`)); err == nil { + t.Errorf("error must be non-nil but was nil") + } + + if _, err := NewShader([]byte(`package main + +func Fragment(position vec4, texCoord vec2, color vec4) vec4 { + _++ + return vec4(0) +} `)); err == nil { t.Errorf("error must be non-nil but was nil") }