internal/shader: bug fix: a meaningless statement should raise an error

Closes #1898
This commit is contained in:
Hajime Hoshi 2021-12-27 22:05:55 +09:00
parent dd4d2f6aa0
commit 481a2145ae
2 changed files with 20 additions and 0 deletions

View File

@ -471,8 +471,13 @@ func (cs *compileState) parseStmt(block *block, fname string, stmt ast.Stmt, inP
for _, expr := range exprs {
if expr.Type != shaderir.Call {
// TODO: Should this return an error?
continue
}
if expr.Exprs[0].Type == shaderir.BuiltinFuncExpr {
cs.addError(stmt.Pos(), fmt.Sprintf("the statement is evaluated but not used"))
return nil, false
}
stmts = append(stmts, shaderir.Stmt{
Type: shaderir.ExprStmt,
Exprs: []shaderir.Expr{expr},

View File

@ -1242,3 +1242,18 @@ func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
t.Errorf("error must be non-nil but was nil")
}
}
// Issue #1898
func TestShaderMeaninglessSentence(t *testing.T) {
if _, err := ebiten.NewShader([]byte(`package main
var Time float
var ScreenSize vec2
func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
vec2(position)
return position
}`)); err == nil {
t.Errorf("error must be non-nil but was nil")
}
}