shader: Bug fix: Checking unused variables defined with var

This commit is contained in:
Hajime Hoshi 2020-09-17 17:29:31 +09:00
parent e764b3a425
commit 4d3d3134d5
2 changed files with 24 additions and 2 deletions

View File

@ -322,9 +322,11 @@ func (cs *compileState) parseDecl(b *block, d ast.Decl) ([]shaderir.Stmt, bool)
continue continue
} }
base := b.totalLocalVariableNum() for _, v := range vs {
b.vars = append(b.vars, vs...) b.addNamedLocalVariable(v.name, v.typ, d.Pos())
}
base := b.totalLocalVariableNum()
if len(inits) > 0 { if len(inits) > 0 {
for i := range vs { for i := range vs {
stmts = append(stmts, shaderir.Stmt{ stmts = append(stmts, shaderir.Stmt{

View File

@ -588,6 +588,26 @@ func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
`)); err != nil { `)); err != nil {
t.Error(err) t.Error(err)
} }
if _, err := NewShader([]byte(`package main
func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
var a int
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 {
var a, b int
return vec4(0)
}
`)); err == nil {
t.Errorf("error must be non-nil but was nil")
}
} }
func TestShaderBlankLhs(t *testing.T) { func TestShaderBlankLhs(t *testing.T) {