Repository: go
Issue: runtime: type-assertion on Safari/WASM sometimes generates "types from different scopes"
Labels: NeedsInvestigation,arch-wasm,compiler/runtime

<!--
Please answer these questions before submitting your issue. Thanks!
For questions please use one of our forums: https://github.com/golang/go/wiki/Questions
-->

### What version of Go are you using (`go version`)?

<pre>
go version go1.16.5 windows/amd64
</pre>

### Does this issue reproduce with the latest release?

Yes

### What operating system and processor architecture are you using (`go env`)?

<details><summary><code>go env</code> Output</summary><br><pre>
set GO111MODULE=
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\lucas\AppData\Local\go-build
set GOENV=C:\Users\lucas\AppData\Roaming\go\env
set GOEXE=.exe
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GOMODCACHE=Z:\GOPATH\pkg\mod
set GONOPROXY=
set GONOSUMDB=
set GOOS=windows
set GOPATH=Z:\GOPATH
set GOPRIVATE=
set GOPROXY=https://proxy.golang.org,direct
set GOROOT=c:\go
set GOSUMDB=sum.golang.org
set GOTMPDIR=
set GOTOOLDIR=c:\go\pkg\tool\windows_amd64
set GOVCS=
set GOVERSION=go1.16.5
set GCCGO=gccgo
set AR=ar
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=NUL
set CGO_CFLAGS=-g -O2
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-g -O2
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -mthreads -fmessage-length=0 -fdebug-prefix-map=C:\Users\lucas\AppData\Local\Temp\go-build1684762088=/tmp/go-build -gno-record-gcc-switches
</pre></details>

### What did you do?

It's dificult to reproduce the issue, I tried to create many structs and all of them works. In my program I use the following construction:

	if resp, ok,_ := sp.Request.Result(); ok {
  	    if resp, ok := resp.(*common.OrderCreateResponse); ok {
                //...
           }
        }

The `sp.Request.Result()` returns a `interface{}` which contains the decoded body from http request. For every response, I use the type-assertion. So, for Login page it may have something like `*common.LoginResponse` and on SignUp it will use `*common.SignUpResponse`, for instance.

On all platforms, the code works, **except on Safari/WebAssembly**. The code works on many cases (say `*common.OrderCreateResponse` works, but `*common.SignUpResponse` doesn't). That is why is so difficult to create a test or to provide a code to reproduce the issue.

### What did you expect to see?

The same behavior of all other OSes (including the WebAssembly on Chrome/Windows). On all other OSes (Windows, Linux, Android) and also on WebAssembly runing on Windows and Android: the `ok` from the type-assertion is `true`.

### What did you see instead?

The `ok` on type-assertion returns `false` on Safari/WebAssembly. However, the `resp` of the same type-assertion is a non-nil value, which contains the data/struct correctly.

--------------------------

### More tests and weird results:

1. **Removing the  `ok`: (fail)**

```
resp := resp.(*common.OrderCreateResponse)
```

It works on all OSes, except on Safari, which gives: 

```
panic: interface conversion: interface {} is *common.OrderCreateResponse, not *common.OrderCreateResponse (types from different scopes)
```


2. **Ignoring the `ok`: (works)**

```
if resp, _ := resp.(*common.OrderCreateResponse); resp != nil {
fmt.Println("ok", resp)
}
```

It works everywhere, including Safari. The `resp` is a non-nil! Notice that I'm using `resp, _ :=` instead of `resp :=`.

3. **Switch type: (works)**

```
switch resp := resp.(type) {
    case *common.OrderCreateResponse:
    fmt.Println("ok", resp)
}
```

It works everywhere, including Safari.

4. Using `reflect` before the type-assertion (works):

```
if resp, ok,_ := sp.Request.Result(); ok {
    fmt.Println("resp",  reflect.TypeOf(resp).String())                                                       // Prints: *common.OrderCreateResponse
    fmt.Println("base",  reflect.TypeOf(new(common.OrderCreateResponse)).String())  // Prints: *common.OrderCreateResponse

    if resp, ok := resp.(*common.OrderCreateResponse); ok {
        fmt.Println("ok", resp) // It works now!
    }
}
```

For some random reason, **that works** on Safari! When I insert the prints, the `resp.(*common.OrderCreateResponse)` returns `ok=true`, for some unknown reason.