shader: Bug fix: Ignore blank identifiers for the duplication check

Fixes #1330
This commit is contained in:
Hajime Hoshi 2020-09-03 01:27:28 +09:00
parent 4ac11bf156
commit 55f0c983ba
3 changed files with 49 additions and 8 deletions

View File

@ -470,10 +470,12 @@ func (cs *compileState) assign(block *block, pos token.Pos, lhs, rhs []ast.Expr,
if define {
name := e.(*ast.Ident).Name
for _, v := range block.vars {
if v.name == name {
cs.addError(pos, fmt.Sprintf("duplicated local variable name: %s", name))
return nil, false
if name != "_" {
for _, v := range block.vars {
if v.name == name {
cs.addError(pos, fmt.Sprintf("duplicated local variable name: %s", name))
return nil, false
}
}
}
ts, ok := cs.functionReturnTypes(block, rhs[i])
@ -573,10 +575,12 @@ func (cs *compileState) assign(block *block, pos token.Pos, lhs, rhs []ast.Expr,
if define {
name := e.(*ast.Ident).Name
for _, v := range block.vars {
if v.name == name {
cs.addError(pos, fmt.Sprintf("duplicated local variable name: %s", name))
return nil, false
if name != "_" {
for _, v := range block.vars {
if v.name == name {
cs.addError(pos, fmt.Sprintf("duplicated local variable name: %s", name))
return nil, false
}
}
}
v := variable{

View File

@ -0,0 +1,26 @@
void F0(out int l0, out int l1);
void F1(void);
void F0(out int l0, out int l1) {
l0 = 1;
l1 = 1;
return;
}
void F1(void) {
int l0 = 0;
int l1 = 0;
int l2 = 0;
int l3 = 0;
int l4 = 0;
int l5 = 0;
int l6 = 0;
int l7 = 0;
int l8 = 0;
int l9 = 0;
F0(l0, l1);
F0(l2, l3);
l4 = l2;
F0(l6, l7);
l9 = l7;
}

11
internal/shader/testdata/blank.go vendored Normal file
View File

@ -0,0 +1,11 @@
package main
func Foo() (int, int) {
return 1, 1
}
func Bar() {
_, _ = Foo()
a, _ := Foo()
_, b := Foo()
}