mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-24 10:48:53 +01:00
internal/shader: check type redeclaration
This commit is contained in:
parent
0c19b8d7ae
commit
7f91a681e3
@ -315,8 +315,15 @@ func (cs *compileState) parseDecl(b *block, fname string, d ast.Decl) ([]shaderi
|
|||||||
if !ok {
|
if !ok {
|
||||||
return nil, false
|
return nil, false
|
||||||
}
|
}
|
||||||
|
n := s.Name.Name
|
||||||
|
for _, t := range b.types {
|
||||||
|
if t.name == n {
|
||||||
|
cs.addError(s.Pos(), fmt.Sprintf("%s redeclared in this block", n))
|
||||||
|
return nil, false
|
||||||
|
}
|
||||||
|
}
|
||||||
b.types = append(b.types, typ{
|
b.types = append(b.types, typ{
|
||||||
name: s.Name.Name,
|
name: n,
|
||||||
ir: t,
|
ir: t,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -2381,3 +2381,30 @@ func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestTypeRedeclaration(t *testing.T) {
|
||||||
|
cases := []struct {
|
||||||
|
stmt string
|
||||||
|
err bool
|
||||||
|
}{
|
||||||
|
{stmt: "type Foo int; type Foo int", err: true},
|
||||||
|
{stmt: "type Foo int; type Foo float", err: true},
|
||||||
|
{stmt: "type Foo int; type Bar int", err: false},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, c := range cases {
|
||||||
|
stmt := c.stmt
|
||||||
|
src := fmt.Sprintf(`package main
|
||||||
|
|
||||||
|
func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
||||||
|
%s
|
||||||
|
return position
|
||||||
|
}`, stmt)
|
||||||
|
_, err := compileToIR([]byte(src))
|
||||||
|
if err == nil && c.err {
|
||||||
|
t.Errorf("%s must return an error but does not", stmt)
|
||||||
|
} else if err != nil && !c.err {
|
||||||
|
t.Errorf("%s must not return nil but returned %v", stmt, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user