mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 04:57:26 +01:00
internal/shader: bug fix: untyped const bool couldn't be an if condition
Closes #2993
This commit is contained in:
parent
09cefc6e71
commit
5d47863a27
@ -251,7 +251,7 @@ func (cs *compileState) parseStmt(block *block, fname string, stmt ast.Stmt, inP
|
|||||||
if !ok {
|
if !ok {
|
||||||
return nil, false
|
return nil, false
|
||||||
}
|
}
|
||||||
if len(ts) != 1 || ts[0].Main != shaderir.Bool {
|
if len(ts) != 1 {
|
||||||
var tss []string
|
var tss []string
|
||||||
for _, t := range ts {
|
for _, t := range ts {
|
||||||
tss = append(tss, t.String())
|
tss = append(tss, t.String())
|
||||||
@ -259,6 +259,10 @@ func (cs *compileState) parseStmt(block *block, fname string, stmt ast.Stmt, inP
|
|||||||
cs.addError(stmt.Pos(), fmt.Sprintf("if-condition must be bool but: %s", strings.Join(tss, ", ")))
|
cs.addError(stmt.Pos(), fmt.Sprintf("if-condition must be bool but: %s", strings.Join(tss, ", ")))
|
||||||
return nil, false
|
return nil, false
|
||||||
}
|
}
|
||||||
|
if !(ts[0].Main == shaderir.Bool || (ts[0].Main == shaderir.None && exprs[0].Const != nil && exprs[0].Const.Kind() == gconstant.Bool)) {
|
||||||
|
cs.addError(stmt.Pos(), fmt.Sprintf("if-condition must be bool but: %s", ts[0].String()))
|
||||||
|
return nil, false
|
||||||
|
}
|
||||||
stmts = append(stmts, ss...)
|
stmts = append(stmts, ss...)
|
||||||
|
|
||||||
var bs []*shaderir.Block
|
var bs []*shaderir.Block
|
||||||
|
@ -4335,3 +4335,31 @@ func Bar() float {
|
|||||||
t.Error("compileToIR must return an error but did not")
|
t.Error("compileToIR must return an error but did not")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Issue #2993
|
||||||
|
func TestSyntaxIfAndConstBool(t *testing.T) {
|
||||||
|
if _, err := compileToIR([]byte(`package main
|
||||||
|
|
||||||
|
func Foo() int {
|
||||||
|
const X = true
|
||||||
|
if X {
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
`)); err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
}
|
||||||
|
if _, err := compileToIR([]byte(`package main
|
||||||
|
|
||||||
|
func Foo() int {
|
||||||
|
const X bool = true
|
||||||
|
if X {
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
`)); err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user