gopherdata / gophernotes

The Go kernel for Jupyter notebooks and nteract.
MIT License
3.8k stars 262 forks source link

Error `not a package: "h" in h.Write <*ast.SelectorExpr>` when `h` is a variable and the code is otherwise valid #240

Closed codemicro closed 2 years ago

codemicro commented 2 years ago

When attempting to run the following snippet using Nteract and the latest version of GopherNotes, I get the following error:

import "crypto/hmac"
import "crypto/sha1"

h := hmac.New(sha1.New, []byte("bananarama"))
_, _ = h.Write([]byte("some data"))
h.Sum(nil)
repl.go:5:8: not a package: "h" in h.Write <*ast.SelectorExpr>

However, if I try to compile and run the following using the go run command, I get no error, and it runs without a hitch:

package main

import "crypto/hmac"
import "crypto/sha1"

func main() {
h := hmac.New(sha1.New, []byte("bananarama"))
_, _ = h.Write([]byte("some data"))
h.Sum(nil)
}
cosmos72 commented 2 years ago

Confirmed, it's a bug. For some reason, the interpreter thinks h has no methods at all:

import "crypto/hmac"
import "crypto/sha1"

h := hmac.New(sha1.New, []byte("bananarama"))
h.Write
repl.go:1:1: type hash.Hash has no field or method "Write": h.Write

I will investigate this.

codemicro commented 2 years ago

Thanks for the quick response and the fix @cosmos72 :)

cosmos72 commented 2 years ago

Fixed in version v0.7.4