mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 04:57:26 +01:00
internal/shader: bug fix: forbid duplicated uniform variables
Closes #2648
This commit is contained in:
parent
446a6dc952
commit
1269315f75
@ -407,6 +407,12 @@ func (cs *compileState) parseDecl(b *block, fname string, d ast.Decl) ([]shaderi
|
||||
cs.addError(s.Names[i].Pos(), fmt.Sprintf("global variables must be exposed: %s", v.name))
|
||||
}
|
||||
}
|
||||
for _, name := range cs.ir.UniformNames {
|
||||
if name == v.name {
|
||||
cs.addError(s.Pos(), fmt.Sprintf("%s redeclared in this block", name))
|
||||
return nil, false
|
||||
}
|
||||
}
|
||||
cs.ir.UniformNames = append(cs.ir.UniformNames, v.name)
|
||||
cs.ir.Uniforms = append(cs.ir.Uniforms, v.typ)
|
||||
}
|
||||
|
@ -3543,3 +3543,46 @@ func foo() {
|
||||
t.Error("compileToIR must return an error but did not")
|
||||
}
|
||||
}
|
||||
|
||||
// Issue #2648
|
||||
func TestDuplicatedVariables(t *testing.T) {
|
||||
if _, err := compileToIR([]byte(`package main
|
||||
|
||||
var Foo int
|
||||
var Foo int
|
||||
`)); err == nil {
|
||||
t.Error("compileToIR must return an error but did not")
|
||||
}
|
||||
if _, err := compileToIR([]byte(`package main
|
||||
|
||||
var Foo int
|
||||
var Bar float
|
||||
var Foo vec2
|
||||
`)); err == nil {
|
||||
t.Error("compileToIR must return an error but did not")
|
||||
}
|
||||
if _, err := compileToIR([]byte(`package main
|
||||
|
||||
func foo() {
|
||||
var x int
|
||||
var x int
|
||||
_ = x
|
||||
}
|
||||
|
||||
`)); err == nil {
|
||||
t.Error("compileToIR must return an error but did not")
|
||||
}
|
||||
if _, err := compileToIR([]byte(`package main
|
||||
|
||||
func foo() {
|
||||
var x int
|
||||
var y float
|
||||
var x vec2
|
||||
_ = x
|
||||
_ = y
|
||||
}
|
||||
|
||||
`)); err == nil {
|
||||
t.Error("compileToIR must return an error but did not")
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user