diff --git a/internal/shader/stmt.go b/internal/shader/stmt.go index 1196f7689..e25ee8f28 100644 --- a/internal/shader/stmt.go +++ b/internal/shader/stmt.go @@ -639,6 +639,15 @@ func (cs *compileState) assign(block *block, fname string, pos token.Pos, lhs, r } stmts = append(stmts, ss...) + if len(l) != len(r) { + if len(r) == 0 { + cs.addError(pos, fmt.Sprintf("right-hand side (no value) used as value")) + } else { + cs.addError(pos, fmt.Sprintf("assignment mismatch: %d variables but the right-hand side has %d values", len(l), len(r))) + } + return nil, false + } + if l[0].Type == shaderir.Blank { continue } diff --git a/internal/shader/syntax_test.go b/internal/shader/syntax_test.go index 93327a738..290da0317 100644 --- a/internal/shader/syntax_test.go +++ b/internal/shader/syntax_test.go @@ -3122,3 +3122,19 @@ func Fragment(position vec4, texCoord vec2, color vec4) vec4 { } } } + +// Issue #2654 +func TestOmittedReturnType(t *testing.T) { + if _, err := compileToIR([]byte(`package main + +func foo(x vec2) { + x = bar(x) + _ = x +} + +func bar(x vec2) { + return x +}`)); err == nil { + t.Error("compileToIR must return an error but did not") + } +}