mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-02-09 09:24:43 +01:00
internal/shader: bug fix: wrong for-loop should fail compilation
Closes #2680
This commit is contained in:
parent
98cb77d94f
commit
2de54c556b
@ -214,7 +214,7 @@ func (cs *compileState) parseStmt(block *block, fname string, stmt ast.Stmt, inP
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Create a new pseudo block for the initial statement, so that the counter variable belongs to the
|
// Create a new pseudo block for the initial statement, so that the counter variable belongs to the
|
||||||
// new pseudo block for each for-loop. Without this, the samely named counter variables in different
|
// new pseudo block for each for-loop. Without this, the same-named counter variables in different
|
||||||
// for-loops confuses the parser.
|
// for-loops confuses the parser.
|
||||||
pseudoBlock, ok := cs.parseBlock(block, fname, []ast.Stmt{stmt.Init}, inParams, outParams, returnType, false)
|
pseudoBlock, ok := cs.parseBlock(block, fname, []ast.Stmt{stmt.Init}, inParams, outParams, returnType, false)
|
||||||
if !ok {
|
if !ok {
|
||||||
@ -240,6 +240,11 @@ func (cs *compileState) parseStmt(block *block, fname string, stmt ast.Stmt, inP
|
|||||||
return nil, false
|
return nil, false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if len(pseudoBlock.vars) != 1 {
|
||||||
|
cs.addError(stmt.Pos(), msg)
|
||||||
|
return nil, false
|
||||||
|
}
|
||||||
|
|
||||||
vartype := pseudoBlock.vars[0].typ
|
vartype := pseudoBlock.vars[0].typ
|
||||||
init := ss[0].Exprs[1].Const
|
init := ss[0].Exprs[1].Const
|
||||||
|
|
||||||
|
@ -3521,3 +3521,25 @@ func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Issue #2680
|
||||||
|
func TestForWithLocalVariable(t *testing.T) {
|
||||||
|
if _, err := compileToIR([]byte(`package main
|
||||||
|
|
||||||
|
func foo() {
|
||||||
|
i := 0
|
||||||
|
for i = 0; i < 1; i++ {
|
||||||
|
}
|
||||||
|
}`)); err == nil {
|
||||||
|
t.Error("compileToIR must return an error but did not")
|
||||||
|
}
|
||||||
|
if _, err := compileToIR([]byte(`package main
|
||||||
|
|
||||||
|
func foo() {
|
||||||
|
for i, j := 0, 0; i < 1; i++ {
|
||||||
|
_ = j
|
||||||
|
}
|
||||||
|
}`)); err == nil {
|
||||||
|
t.Error("compileToIR must return an error but did not")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user