mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 04:57:26 +01:00
shader: Reland: Bug fix: Checking unused variables defined with var
This commit is contained in:
parent
ac971f77c5
commit
ab004031d0
@ -322,8 +322,11 @@ func (cs *compileState) parseDecl(b *block, d ast.Decl) ([]shaderir.Stmt, bool)
|
||||
continue
|
||||
}
|
||||
|
||||
// base must be obtained before adding the variables.
|
||||
base := b.totalLocalVariableNum()
|
||||
b.vars = append(b.vars, vs...)
|
||||
for _, v := range vs {
|
||||
b.addNamedLocalVariable(v.name, v.typ, d.Pos())
|
||||
}
|
||||
|
||||
if len(inits) > 0 {
|
||||
for i := range vs {
|
||||
|
1
internal/shader/testdata/array2.go
vendored
1
internal/shader/testdata/array2.go
vendored
@ -5,6 +5,7 @@ func Foo() [3]vec2 {
|
||||
{
|
||||
var b [2]vec2
|
||||
b = a
|
||||
_ = b
|
||||
}
|
||||
var c [3]vec2
|
||||
return c
|
||||
|
1
internal/shader/testdata/blocks3.go
vendored
1
internal/shader/testdata/blocks3.go
vendored
@ -15,6 +15,7 @@ func Foo(foo vec2) vec4 {
|
||||
r.y = foo.y
|
||||
var foo vec4
|
||||
r.z = bar.z
|
||||
_ = foo
|
||||
}
|
||||
}
|
||||
return r
|
||||
|
@ -588,6 +588,26 @@ func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
||||
`)); err != nil {
|
||||
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) {
|
||||
|
Loading…
Reference in New Issue
Block a user