Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

convert a function to another type #936

Closed
mvertes opened this issue Nov 3, 2020 · 0 comments · Fixed by #937
Closed

convert a function to another type #936

mvertes opened this issue Nov 3, 2020 · 0 comments · Fixed by #937
Assignees
Labels
area/core bug Something isn't working
Milestone

Comments

@mvertes
Copy link
Member

mvertes commented Nov 3, 2020

The following program sample.go triggers a panic:

package main

type T struct {
    v int 
}

type comparator func(T, T) bool

func sort(items []T, comp comparator) {
    println("in sort")
}

func compT(t0, t1 T) bool { return t0.v < t1.v }

func main() {
    a := []T{}
    sort(a, comparator(compT))
}

Expected result:

$ go run ./sample.go
in sort

Got:

$ yaegi ./sample.go
./sample.go:17:10: panic
run: reflect.Set: value of type func(struct { Xv int }, struct { Xv int }) bool is not assignable to type *interp.node
goroutine 1 [running]:
runtime/debug.Stack(0x1, 0xc000186a00, 0x40)
        /usr/lib/go/src/runtime/debug/stack.go:24 +0x9f
github.com/traefik/yaegi/interp.(*Interpreter).eval.func1(0xc000219c70)
        /home/marc/go/src/github.com/traefik/yaegi/interp/interp.go:480 +0xc5
panic(0xdceac0, 0xc0001bf220)
        /usr/lib/go/src/runtime/panic.go:969 +0x1b9
github.com/traefik/yaegi/interp.runCfg.func1(0xc0001ce820, 0xc000482900, 0xc000219a60)
        /home/marc/go/src/github.com/traefik/yaegi/interp/run.go:171 +0x247
panic(0xdceac0, 0xc0001bf220)
        /usr/lib/go/src/runtime/panic.go:969 +0x1b9
reflect.Value.assignTo(0xc000137080, 0xc000405a10, 0x13, 0xf087a3, 0xb, 0xea6680, 0x0, 0xc000137080, 0xc000480c00, 0x0)
        /usr/lib/go/src/reflect/value.go:2425 +0x405
reflect.Value.Set(0xea6680, 0xc0001348d8, 0x196, 0xc000137080, 0xc000405a10, 0x13)
        /usr/lib/go/src/reflect/value.go:1554 +0xbd
github.com/traefik/yaegi/interp.convert.func3(0xc0001ce820, 0xc0001dcc00)
        /home/marc/go/src/github.com/traefik/yaegi/interp/run.go:418 +0x1ce
github.com/traefik/yaegi/interp.runCfg(0xc000482900, 0xc0001ce820)
        /home/marc/go/src/github.com/traefik/yaegi/interp/run.go:177 +0x87
github.com/traefik/yaegi/interp.(*Interpreter).run(0xc00037e000, 0xc000482100, 0xc0001ce780)
        /home/marc/go/src/github.com/traefik/yaegi/interp/run.go:108 +0x2af
github.com/traefik/yaegi/interp.(*Interpreter).eval(0xc00037e000, 0xc00010c900, 0xf2, 0x7ffd515665c3, 0x19, 0x0, 0x0, 0x0, 0x0, 0x0, ...)
        /home/marc/go/src/github.com/traefik/yaegi/interp/interp.go:572 +0x809
github.com/traefik/yaegi/interp.(*Interpreter).EvalPath(0xc00037e000, 0x7ffd515665c3, 0x19, 0xc00010c800, 0xf2, 0x0, 0x0, 0xc00019bba0)
        /home/marc/go/src/github.com/traefik/yaegi/interp/interp.go:394 +0xfa
main.runFile(0xc00037e000, 0x7ffd515665c3, 0x19, 0xc000136de0, 0x1)
        /home/marc/go/src/github.com/traefik/yaegi/cmd/yaegi/run.go:123 +0xae
main.run(0xc000128030, 0x1, 0x1, 0x13, 0x13)
        /home/marc/go/src/github.com/traefik/yaegi/cmd/yaegi/run.go:89 +0x7e5
main.main()
        /home/marc/go/src/github.com/traefik/yaegi/cmd/yaegi/yaegi.go:144 +0x415
@mvertes mvertes added area/core bug Something isn't working labels Nov 3, 2020
@mvertes mvertes added this to the v0.9.x milestone Nov 3, 2020
@mvertes mvertes self-assigned this Nov 3, 2020
mvertes added a commit that referenced this issue Nov 3, 2020
Interpreter function types are represented internally by the AST node
of their definition. The conversion operation creates a new node with
the type field pointing to the target type.

Fixes #936.
traefiker pushed a commit that referenced this issue Nov 3, 2020
Interpreter function types are represented internally by the AST node
of their definition. The conversion operation creates a new node with
the type field pointing to the target type.

Fixes #936.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/core bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant