简体   繁体   English

不能将 lib.Const(lib.Version 类型的常量 16777216)用作 lib.Version

[英]Cannot use lib.Const (constant 16777216 of type lib.Version) as lib.Version

I've come across an odd error.我遇到了一个奇怪的错误。 I have this larger project that compiles fine with the typical go build .我有这个较大的项目,可以使用典型的go build进行良好编译。 However when I switch to TinyGo (v0.8.0).但是,当我切换到 TinyGo (v0.8.0) 时。 I get the above error from this code:我从这段代码中得到了上述错误:

func main() {

    _ = lib.NewObject{
         Version: lib.Const,
    }
}

I changed the names to be less confusing but the symbols are completely identical.我更改了名称以减少混淆,但符号完全相同。 lib.Const is a constant of a lib.Version . lib.Constlib.Version的常量。 And neither are pointers.指针也不是。

I understand this is a very specific question in the sense that it's in the realm TinyGo.我知道这是一个非常具体的问题,因为它在 realm TinyGo 中。 This is more "for the record"... plus I even had to create the "tinygo" tag because this question is so specific.这更像是“记录在案”......而且我什至不得不创建“tinygo”标签,因为这个问题非常具体。 But to add further detail:但要添加更多细节:

  • It has been compiling before the above code was added.在添加上述代码之前,它一直在编译。
  • The build command in exact is tinygo build -target=wasm -o build/out.wasm src/main-wasm.go确切的构建命令是tinygo build -target=wasm -o build/out.wasm src/main-wasm.go

This is a bug with the compiler: https://github.com/tinygo-org/tinygo/issues/726这是编译器的一个错误: https://github.com/tinygo-org/tinygo/issues/726

It stems from importing the same package twice under different names.它源于以不同的名称两次导入相同的 package。 In this case, it was:在这种情况下,它是:

// file1:
import "./lib"

// file2:
import "../lib"

The above made 2 instances of the package "lib".以上制作了 package“lib”的 2 个实例。 This is normally okay to do when working with the normal Go compiler.使用普通 Go 编译器时,通常可以这样做。 But TinyGo does not have mechanisms in place to deal with this properly.但是 TinyGo 没有适当的机制来处理这个问题。

It is recommended to append to the $GOPATH to prevent the use of relative paths:建议将 append 到$GOPATH以防止使用相对路径:

// file1:
import "lib"

// file2:
import "lib"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM