Skip to content

Commit

Permalink
interp: fix wrapping of returned closure passed to runtime
Browse files Browse the repository at this point in the history
Fixes #1333.
  • Loading branch information
mvertes committed Dec 21, 2021
1 parent 2819b41 commit fbee2ba
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 2 deletions.
37 changes: 37 additions & 0 deletions _test/issue-1333.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package main

import (
"fmt"
"io"
"net/http"
"net/http/httptest"
)

func mock(name string) http.HandlerFunc {
return func(rw http.ResponseWriter, req *http.Request) {
fmt.Fprint(rw, "Hello ", name)
}
}

func client(uri string) {
resp, err := http.Get(uri)
if err != nil {
panic(err)
}
body, err := io.ReadAll(resp.Body)
if err != nil {
panic(err)
}
fmt.Println(string(body))
}

func main() {
mux := http.NewServeMux()
server := httptest.NewServer(mux)
defer server.Close()
mux.Handle("/", mock("foo"))
client(server.URL)
}

// Output:
// Hello foo
8 changes: 6 additions & 2 deletions interp/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -2375,9 +2375,13 @@ func _return(n *node) {
}
values[i] = genValueInterface(c)
case valueT:
if t.rtype.Kind() == reflect.Interface {
switch t.rtype.Kind() {
case reflect.Interface:
values[i] = genInterfaceWrapper(c, t.rtype)
break
continue
case reflect.Func:
values[i] = genFunctionWrapper(c)
continue
}
fallthrough
default:
Expand Down

0 comments on commit fbee2ba

Please sign in to comment.