mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 04:57:26 +01:00
shader: Check the existence of 'return'
This commit is contained in:
parent
0830e897fc
commit
4308bbbc31
@ -645,6 +645,28 @@ func (cs *compileState) parseFunc(block *block, d *ast.FuncDecl) (function, bool
|
||||
return function{}, false
|
||||
}
|
||||
|
||||
if len(outParams) > 0 {
|
||||
var hasReturn func(stmts []shaderir.Stmt) bool
|
||||
hasReturn = func(stmts []shaderir.Stmt) bool {
|
||||
for _, stmt := range stmts {
|
||||
if stmt.Type == shaderir.Return {
|
||||
return true
|
||||
}
|
||||
for _, b := range stmt.Blocks {
|
||||
if hasReturn(b.Stmts) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
if !hasReturn(b.ir.Stmts) {
|
||||
cs.addError(d.Pos(), fmt.Sprintf("function %s must have a return statement but not", d.Name))
|
||||
return function{}, false
|
||||
}
|
||||
}
|
||||
|
||||
var inT, outT []shaderir.Type
|
||||
for _, v := range inParams {
|
||||
inT = append(inT, v.typ)
|
||||
|
2
internal/shader/testdata/func.expected.vs
vendored
2
internal/shader/testdata/func.expected.vs
vendored
@ -1,4 +1,6 @@
|
||||
void F0(in vec2 l0, out vec4 l1);
|
||||
|
||||
void F0(in vec2 l0, out vec4 l1) {
|
||||
l1 = vec4(0.0);
|
||||
return;
|
||||
}
|
||||
|
1
internal/shader/testdata/func.go
vendored
1
internal/shader/testdata/func.go
vendored
@ -1,4 +1,5 @@
|
||||
package main
|
||||
|
||||
func Foo(foo vec2) vec4 {
|
||||
return vec4(0)
|
||||
}
|
||||
|
@ -259,6 +259,26 @@ func Foo() (float, float) {
|
||||
func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
||||
return vec4(0);
|
||||
}
|
||||
`)); err == nil {
|
||||
t.Errorf("error must be non-nil but was nil")
|
||||
}
|
||||
|
||||
if _, err := NewShader([]byte(`package main
|
||||
|
||||
func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
||||
}
|
||||
`)); err == nil {
|
||||
t.Errorf("error must be non-nil but was nil")
|
||||
}
|
||||
|
||||
if _, err := NewShader([]byte(`package main
|
||||
|
||||
func Foo() float {
|
||||
}
|
||||
|
||||
func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
||||
return vec4(0)
|
||||
}
|
||||
`)); err == nil {
|
||||
t.Errorf("error must be non-nil but was nil")
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user