diff --git a/internal/shader/shader.go b/internal/shader/shader.go index 1ad5fa093..f96a25178 100644 --- a/internal/shader/shader.go +++ b/internal/shader/shader.go @@ -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, "__") { diff --git a/internal/shader/syntax_test.go b/internal/shader/syntax_test.go index 1168d86c6..82c32f6d2 100644 --- a/internal/shader/syntax_test.go +++ b/internal/shader/syntax_test.go @@ -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