internal/shader: Make function duplications error

Closes #1430
This commit is contained in:
Hajime Hoshi 2021-02-07 22:24:20 +09:00
parent d999b4dc8e
commit 5f81065d78
2 changed files with 24 additions and 0 deletions

View File

@ -235,6 +235,13 @@ func (cs *compileState) parse(f *ast.File) {
continue
}
for _, f := range cs.funcs {
if f.name == n {
cs.addError(d.Pos(), fmt.Sprintf("redeclared function: %s", n))
return
}
}
inParams, outParams := cs.parseFuncParams(&cs.global, fd)
var inT, outT []shaderir.Type
for _, v := range inParams {

View File

@ -251,6 +251,23 @@ func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
}
}
func TestShaderDuplicatedFunctions(t *testing.T) {
if _, err := NewShader([]byte(`package main
func Foo() {
}
func Foo() {
}
func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
return vec4(0)
}
`)); err == nil {
t.Errorf("error must be non-nil but was nil")
}
}
func TestShaderNoMain(t *testing.T) {
if _, err := NewShader([]byte(`package main
`)); err == nil {