mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 04:57:26 +01:00
internal/shader: bug fix: forbide assigning to a uniform variable
Closes #2648
This commit is contained in:
parent
0785502be3
commit
ad23ae81c1
@ -74,6 +74,11 @@ func (cs *compileState) parseStmt(block *block, fname string, stmt ast.Stmt, inP
|
||||
}
|
||||
stmts = append(stmts, ss...)
|
||||
|
||||
if lhs[0].Type == shaderir.UniformVariable {
|
||||
cs.addError(stmt.Pos(), fmt.Sprintf("a uniform variable cannot be assigned"))
|
||||
return nil, false
|
||||
}
|
||||
|
||||
var op shaderir.Op
|
||||
switch stmt.Tok {
|
||||
case token.ADD_ASSIGN:
|
||||
|
@ -3138,3 +3138,38 @@ func bar(x vec2) {
|
||||
t.Error("compileToIR must return an error but did not")
|
||||
}
|
||||
}
|
||||
|
||||
// Issue #2648
|
||||
func TestAssignToUniformVariables(t *testing.T) {
|
||||
if _, err := compileToIR([]byte(`package main
|
||||
|
||||
var Foo float
|
||||
|
||||
func foo(x vec2) {
|
||||
Foo = 0
|
||||
}`)); err == nil {
|
||||
t.Error("compileToIR must return an error but did not")
|
||||
}
|
||||
|
||||
if _, err := compileToIR([]byte(`package main
|
||||
|
||||
var Foo float
|
||||
|
||||
func foo(x vec2) {
|
||||
var x int
|
||||
x, Foo = 0, 0
|
||||
_ = x
|
||||
}`)); err == nil {
|
||||
t.Error("compileToIR must return an error but did not")
|
||||
}
|
||||
|
||||
if _, err := compileToIR([]byte(`package main
|
||||
|
||||
var Foo float
|
||||
|
||||
func foo(x vec2) {
|
||||
Foo += 0
|
||||
}`)); err == nil {
|
||||
t.Error("compileToIR must return an error but did not")
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user