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

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

Closed
codemicro opened this issue Jan 7, 2022 · 3 comments
Assignees
Labels

Comments

@codemicro
Copy link

codemicro commented Jan 7, 2022

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)
}
@codemicro codemicro changed the title repl.go:5:8: not a package: "h" in h.Write <*ast.SelectorExpr> when h is a variable and the code is otherwise valid Error not a package: "h" in h.Write <*ast.SelectorExpr> when h is a variable and the code is otherwise valid Jan 7, 2022
@cosmos72 cosmos72 self-assigned this Jan 7, 2022
@cosmos72 cosmos72 added the bug label Jan 7, 2022
@cosmos72
Copy link
Member

cosmos72 commented Jan 7, 2022

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.

cosmos72 added a commit to cosmos72/gomacro that referenced this issue Jan 9, 2022
`import "hash"` now correctly defines a `hash.Hash` interface containing 5 methods
previously it contained 0 methods.
@codemicro
Copy link
Author

codemicro commented Jan 9, 2022

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

@cosmos72
Copy link
Member

cosmos72 commented Jan 9, 2022

Fixed in version v0.7.4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants