Skip to content

Commit

Permalink
internal/shader: bug fix: forbid to have an initial value for uniform…
Browse files Browse the repository at this point in the history
… variables

Closes #2711
  • Loading branch information
hajimehoshi committed Jul 29, 2023
1 parent 1b8580f commit 4df647a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
5 changes: 5 additions & 0 deletions internal/shader/shader.go
Original file line number Diff line number Diff line change
Expand Up @@ -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, "__") {
Expand Down
14 changes: 14 additions & 0 deletions internal/shader/syntax_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 4df647a

Please sign in to comment.