internal/shader: bug fix: panic when an assignment mismatch happens

Closes #2654
This commit is contained in:
Hajime Hoshi 2023-04-26 22:07:40 +09:00
parent 56b4cdc3c4
commit 2a1d23d926
2 changed files with 25 additions and 0 deletions

View File

@ -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
}

View File

@ -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")
}
}