mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-25 11:18:54 +01:00
internal/shader: bug fix: a meaningless statement should raise an error (a non-call expression statement)
Updates #1898
This commit is contained in:
parent
481a2145ae
commit
374871c031
@ -373,6 +373,7 @@ func (cs *compileState) parseExpr(block *block, expr ast.Expr, markLocalVariable
|
||||
// TODO: Is this an error?
|
||||
}
|
||||
|
||||
// These local-variable expressions are used for an outside function callers.
|
||||
var exprs []shaderir.Expr
|
||||
for _, p := range outParams {
|
||||
exprs = append(exprs, shaderir.Expr{
|
||||
|
@ -463,6 +463,11 @@ func (cs *compileState) parseStmt(block *block, fname string, stmt ast.Stmt, inP
|
||||
}
|
||||
|
||||
case *ast.ExprStmt:
|
||||
if _, ok := stmt.X.(*ast.CallExpr); !ok {
|
||||
cs.addError(stmt.Pos(), fmt.Sprintf("the statement is evaluated but not used"))
|
||||
return nil, false
|
||||
}
|
||||
|
||||
exprs, _, ss, ok := cs.parseExpr(block, stmt.X, true)
|
||||
if !ok {
|
||||
return nil, false
|
||||
@ -470,8 +475,9 @@ func (cs *compileState) parseStmt(block *block, fname string, stmt ast.Stmt, inP
|
||||
stmts = append(stmts, ss...)
|
||||
|
||||
for _, expr := range exprs {
|
||||
// There can be a non-call expr like LocalVariable expressions.
|
||||
// These are necessary to be used as arguments for an outside function callers.
|
||||
if expr.Type != shaderir.Call {
|
||||
// TODO: Should this return an error?
|
||||
continue
|
||||
}
|
||||
if expr.Exprs[0].Type == shaderir.BuiltinFuncExpr {
|
||||
|
@ -1250,6 +1250,18 @@ func TestShaderMeaninglessSentence(t *testing.T) {
|
||||
var Time float
|
||||
var ScreenSize vec2
|
||||
|
||||
func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
||||
position
|
||||
return position
|
||||
}`)); err == nil {
|
||||
t.Errorf("error must be non-nil but was nil")
|
||||
}
|
||||
|
||||
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
|
||||
|
Loading…
Reference in New Issue
Block a user