internal/shader: bug fix: forbid to have an initial value for uniform variables

Closes #2711
This commit is contained in:
Hajime Hoshi 2023-07-29 20:51:00 +09:00
parent 1b8580fab7
commit 4df647a400
2 changed files with 19 additions and 0 deletions

View File

@ -395,6 +395,11 @@ func (cs *compileState) parseDecl(b *block, fname string, d ast.Decl) ([]shaderi
stmts = append(stmts, ss...)
if b == &cs.global {
if len(inits) > 0 {
cs.addError(s.Pos(), "a uniform variable cannot have initial values")
return nil, false
}
// TODO: Should rhs be ignored?
for i, v := range vs {
if !strings.HasPrefix(v.name, "__") {

View File

@ -3260,6 +3260,20 @@ func foo(x vec2) {
}`)); err == nil {
t.Error("compileToIR must return an error but did not")
}
// Issue #2711
if _, err := compileToIR([]byte(`package main
var Foo float = 1
`)); err == nil {
t.Error("compileToIR must return an error but did not")
}
if _, err := compileToIR([]byte(`package main
var Foo, Bar int = 1, 1
`)); err == nil {
t.Error("compileToIR must return an error but did not")
}
}
// Issue #2705