mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-09 20:47:26 +01:00
internal/shader: Check the number of arguments
This commit is contained in:
parent
9be4ce928b
commit
8ae6793d4d
@ -291,6 +291,15 @@ func (cs *compileState) parseExpr(block *block, expr ast.Expr, markLocalVariable
|
||||
|
||||
f := cs.funcs[callee.Index]
|
||||
|
||||
if len(f.ir.InParams) < len(args) {
|
||||
cs.addError(e.Pos(), fmt.Sprintf("too many arguments in call to %s", e.Fun))
|
||||
return nil, nil, nil, false
|
||||
}
|
||||
if len(f.ir.InParams) > len(args) {
|
||||
cs.addError(e.Pos(), fmt.Sprintf("not enough arguments in call to %s", e.Fun))
|
||||
return nil, nil, nil, false
|
||||
}
|
||||
|
||||
for i, p := range f.ir.InParams {
|
||||
if args[i].Type == shaderir.NumberExpr && p.Main == shaderir.Int {
|
||||
if !cs.forceToInt(e, &args[i]) {
|
||||
|
@ -6,7 +6,7 @@ void F0(in vec2 l0, out vec2 l1) {
|
||||
float l3 = float(0);
|
||||
float l4 = float(0);
|
||||
float l5 = float(0);
|
||||
F1((l0).x, (l0).y, l2, l3);
|
||||
F1((l0).x, l2, l3);
|
||||
l4 = l2;
|
||||
l5 = l3;
|
||||
l1 = vec2(l4, l5);
|
||||
|
2
internal/shader/testdata/call_multiple.go
vendored
2
internal/shader/testdata/call_multiple.go
vendored
@ -1,7 +1,7 @@
|
||||
package main
|
||||
|
||||
func Foo(x vec2) vec2 {
|
||||
var xx, yx float = Bar(x.x, x.y)
|
||||
var xx, yx float = Bar(x.x)
|
||||
return vec2(xx, yx)
|
||||
}
|
||||
|
||||
|
@ -1180,3 +1180,18 @@ func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestShaderUnmatchedArgs(t *testing.T) {
|
||||
if _, err := ebiten.NewShader([]byte(`package main
|
||||
|
||||
func Foo() {
|
||||
}
|
||||
|
||||
func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
||||
Foo(1)
|
||||
return position
|
||||
}
|
||||
`)); err == nil {
|
||||
t.Errorf("error must be non-nil but was nil")
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user