mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-26 18:52:44 +01:00
internal/shader: implement strict type checks when calling a function
Closes #2032
This commit is contained in:
parent
15fe7158fd
commit
853d94c3ef
@ -444,6 +444,11 @@ func (cs *compileState) parseExpr(block *block, expr ast.Expr, markLocalVariable
|
||||
return nil, nil, nil, false
|
||||
}
|
||||
}
|
||||
|
||||
if !canAssign(&args[i], &p, &argts[i]) {
|
||||
cs.addError(e.Pos(), fmt.Sprintf("cannot use type %s as type %s in argument", argts[i].String(), p.String()))
|
||||
return nil, nil, nil, false
|
||||
}
|
||||
}
|
||||
|
||||
var outParams []int
|
||||
|
@ -1307,3 +1307,47 @@ func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
||||
t.Errorf("error must be non-nil but was nil")
|
||||
}
|
||||
}
|
||||
|
||||
// Issue #2032
|
||||
func TestSyntaxTypeFuncCall(t *testing.T) {
|
||||
if _, err := compileToIR([]byte(`package main
|
||||
|
||||
func Foo(x vec2) {
|
||||
}
|
||||
|
||||
func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
||||
Foo(0)
|
||||
return color
|
||||
}
|
||||
`)); err == nil {
|
||||
t.Errorf("error must be non-nil but was nil")
|
||||
}
|
||||
if _, err := compileToIR([]byte(`package main
|
||||
|
||||
func Foo(x vec2, y vec3) {
|
||||
}
|
||||
|
||||
func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
||||
Foo(0, 1)
|
||||
return color
|
||||
}
|
||||
`)); err == nil {
|
||||
t.Errorf("error must be non-nil but was nil")
|
||||
}
|
||||
if _, err := compileToIR([]byte(`package main
|
||||
|
||||
func Foo(x vec2, y vec3) {
|
||||
}
|
||||
|
||||
func Bar() (int, int) {
|
||||
return 0, 1
|
||||
}
|
||||
|
||||
func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
||||
Foo(Bar())
|
||||
return color
|
||||
}
|
||||
`)); err == nil {
|
||||
t.Errorf("error must be non-nil but was nil")
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user