mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-24 01:42:05 +01:00
internal/shader: bug fix: error in assinments to multiple variables
Closes #2747
This commit is contained in:
parent
1bbded8653
commit
20ddfba983
@ -620,17 +620,24 @@ func (cs *compileState) assign(block *block, fname string, pos token.Pos, lhs, r
|
|||||||
}
|
}
|
||||||
stmts = append(stmts, ss...)
|
stmts = append(stmts, ss...)
|
||||||
|
|
||||||
|
if len(l) != 1 {
|
||||||
|
cs.addError(pos, fmt.Sprintf("unexpected count of types in lhs: %d", len(l)))
|
||||||
|
return nil, false
|
||||||
|
}
|
||||||
|
if len(lts) != 1 {
|
||||||
|
cs.addError(pos, fmt.Sprintf("unexpected count of expressions in lhs: %d", len(l)))
|
||||||
|
return nil, false
|
||||||
|
}
|
||||||
|
|
||||||
if l[0].Type == shaderir.Blank {
|
if l[0].Type == shaderir.Blank {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
allblank = false
|
allblank = false
|
||||||
|
|
||||||
for i, lt := range lts {
|
if !canAssign(<s[0], &rhsTypes[i], rhsExprs[i].Const) {
|
||||||
if !canAssign(<, &rhsTypes[i], rhsExprs[i].Const) {
|
cs.addError(pos, fmt.Sprintf("cannot use type %s as type %s in variable declaration", rhsTypes[i].String(), lts[0].String()))
|
||||||
cs.addError(pos, fmt.Sprintf("cannot use type %s as type %s in variable declaration", rhsTypes[i].String(), lt.String()))
|
|
||||||
return nil, false
|
return nil, false
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
stmts = append(stmts, shaderir.Stmt{
|
stmts = append(stmts, shaderir.Stmt{
|
||||||
Type: shaderir.Assign,
|
Type: shaderir.Assign,
|
||||||
|
@ -3586,3 +3586,37 @@ func foo() {
|
|||||||
t.Error("compileToIR must return an error but did not")
|
t.Error("compileToIR must return an error but did not")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Issue #2747
|
||||||
|
func TestMultipleAssignmentsAndTypeCheck(t *testing.T) {
|
||||||
|
if _, err := compileToIR([]byte(`package main
|
||||||
|
|
||||||
|
func Foo() (float, bool) {
|
||||||
|
return 0, false
|
||||||
|
}
|
||||||
|
|
||||||
|
func Bar() {
|
||||||
|
f, b := Foo()
|
||||||
|
_, _ = f, b
|
||||||
|
return
|
||||||
|
}
|
||||||
|
`)); err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
}
|
||||||
|
if _, err := compileToIR([]byte(`package main
|
||||||
|
|
||||||
|
func Foo() (float, bool) {
|
||||||
|
return 0, false
|
||||||
|
}
|
||||||
|
|
||||||
|
func Bar() {
|
||||||
|
var f float
|
||||||
|
var b bool
|
||||||
|
f, b = Foo()
|
||||||
|
_, _ = f, b
|
||||||
|
return
|
||||||
|
}
|
||||||
|
`)); err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user