mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 04:57:26 +01:00
internal/shader: bug fix: a meaningless statement should raise an error
Closes #1898
This commit is contained in:
parent
dd4d2f6aa0
commit
481a2145ae
@ -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},
|
||||
|
@ -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")
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user