简体   繁体   中英

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 . However when I switch to 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 . And neither are pointers.

I understand this is a very specific question in the sense that it's in the realm TinyGo. This is more "for the record"... plus I even had to create the "tinygo" tag because this question is so specific. 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

This is a bug with the compiler: https://github.com/tinygo-org/tinygo/issues/726

It stems from importing the same package twice under different names. In this case, it was:

// file1:
import "./lib"

// file2:
import "../lib"

The above made 2 instances of the package "lib". This is normally okay to do when working with the normal Go compiler. But TinyGo does not have mechanisms in place to deal with this properly.

It is recommended to append to the $GOPATH to prevent the use of relative paths:

// file1:
import "lib"

// file2:
import "lib"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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