shader: Forbid init functions

Fixes #1331
This commit is contained in:
Hajime Hoshi 2020-09-12 19:50:20 +09:00
parent de4ff71544
commit ed4a7e1856
2 changed files with 18 additions and 0 deletions

View File

@ -565,6 +565,10 @@ func (cs *compileState) parseFunc(block *block, d *ast.FuncDecl) (function, bool
cs.addError(d.Pos(), "function must have a name")
return function{}, false
}
if d.Name.Name == "init" {
cs.addError(d.Pos(), "init function is not implemented")
return function{}, false
}
if d.Body == nil {
cs.addError(d.Pos(), "function must have a body")
return function{}, false

View File

@ -358,3 +358,17 @@ func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
t.Error(err)
}
}
func TestShaderInit(t *testing.T) {
if _, err := NewShader([]byte(`package main
func init() {
}
func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
return vec4(0)
}
`)); err == nil {
t.Errorf("error must be non-nil but was nil")
}
}