mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-23 17:32:02 +01:00
internal/shader: bug fix: error in assinments to multiple variables
Closes #2747
This commit is contained in:
parent
1bbded8653
commit
20ddfba983
@ -620,16 +620,23 @@ func (cs *compileState) assign(block *block, fname string, pos token.Pos, lhs, r
|
||||
}
|
||||
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 {
|
||||
continue
|
||||
}
|
||||
allblank = false
|
||||
|
||||
for i, lt := range lts {
|
||||
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(), lt.String()))
|
||||
return nil, false
|
||||
}
|
||||
if !canAssign(<s[0], &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()))
|
||||
return nil, false
|
||||
}
|
||||
|
||||
stmts = append(stmts, shaderir.Stmt{
|
||||
|
@ -3586,3 +3586,37 @@ func foo() {
|
||||
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