-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
typecheck doesn't seem to recognise go:wasmimport directives #4956
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
Comments
Hey, thank you for opening your first Issue ! 🙂 If you would like to contribute we have a guide for contributors. |
You need to define the build tags inside the configuration: run:
build-tags:
- wasip1 Also, it's not needed but you can additionally add build tags inside your code: //go:build wasip1
package main
func main() {
result := add(1, 2)
println(result)
}
//go:noescape
//go:wasmimport foo add
func add(a, b int32) int32 |
Perfect. Thank you! |
@ldez - there's still something slightly off. If I have everything in one .golangci.yml
go.mod
main.go package main
import "main/foo"
func main() {
result := foo.Add(1, 2)
println(result)
} foo/add.go package foo
//go:noescape
//go:wasmimport foo add
func Add(a, b int32) int32 output from
Adding the build tag directly in the file doesn't seem to help. |
as a workaround, you can play with build tags. You can remove the build tags from the golancgi-lint configuration and use the following pattern: main.gopackage main
import "github.com/golangci/sandbox/foo"
func main() {
result := foo.Add(1, 2)
println(result)
} foo/add.go//go:build wasip1
package foo
//go:noescape
//go:wasmimport foo add
func Add(a, b int32) int32 foo/add_fake.go//go:build !wasip1
package foo
func Add(a, b int32) int32 {
return a + b
} |
Ok. I can do that for now. Did you want to re-open this then? Or is it an issue for Go itself? |
For now, I don't know where is the problem. |
Understood. Thank you. |
FYI, the workaround with build tags in separate files is actually working quite nicely for me. I can use the "fake" one for mocking the imported functions in unit tests. I think this is the way. 😄 |
Welcome
typecheck
section of the FAQ.Description of the problem
Functions that are marked with
//go:wasmimport
cannot (by design) have a function body. They're simply the declaration for the function that will be imported. However,golangci-lint
fails withmissing function body (typecheck)
.I understand this probably isn't an issue that can be fixed here, but I'm really uncertain where/how to report it elsewhere.
The example program below compiles properly with either Go or TinyGo.
Go:
TinyGo:
But it fails linting with golangci-lint. I also tried staticheck, and it fails in a similar way there too.
Please let me know if I should report this elsewhere also. Thanks.
Version of golangci-lint
golangci-lint has version 1.60.3 built with go1.23.0 from c2e095c on 2024-08-22T21:45:24Z
Configuration
Go environment
Verbose output of running
A minimal reproducible example or link to a public repository
Validation
Supporter
The text was updated successfully, but these errors were encountered: