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

Not correct 'interface contains embedded non-interface' error depending on the order of source files #22580

Closed
michielvi opened this issue Nov 5, 2017 · 15 comments

Comments

@michielvi
Copy link

michielvi commented Nov 5, 2017

What version of Go are you using (go version)?

1.9.2

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

set GOARCH=amd64
set GOBIN=
set GOEXE=.exe
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOOS=windows
set GOPATH=C:\Development\GoWorkspace
set GORACE=
set GOROOT=C:\Development\Go
set GOTOOLDIR=C:\Development\Go\pkg\tool\windows_amd64
set GCCGO=gccgo
set CC=gcc
set GOGCCFLAGS=-m64 -mthreads -fmessage-length=0
set CXX=g++
set CGO_ENABLED=1
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

What did you do?

There is a not correct 'interface contains embedded non-interface' error. When changing the order of file (by renaming them), the error is not anymore there.

To reproduce this error, download gist example in src directory and do 'go build'.

Strange behavior:

  1. The Goat and Chicken interface are exactly the same, however, the error only occurs on the Goat interface.
  2. Rename B.go to D.go and the error is now on both the Goat and the Chicken interface.
  3. Rename Z.go to A.go and there is no error at all.

What did you expect to see?

Never an 'interface contains embedded non-interface' error.

@gbbr
Copy link
Member

gbbr commented Nov 5, 2017

I think people might be hesitant of downloading and unpacking .zip files. Generally it might be better to just place the code in a gist or provide some links to the playground.

@michielvi
Copy link
Author

michielvi commented Nov 6, 2017

Okay, no problem, I have created a gist example and adapted the desciption.

@griesemer
Copy link
Contributor

I cannot reproduce any error. I have created one file for each of your gist code snippets, named as your snippets, all in a clean empty directory. go build builds w/o complaints.

Please clarify how you produced an error by providing step by step instructions, or close this issue. Thanks.

@gbbr
Copy link
Member

gbbr commented Nov 6, 2017

Actually I have just downloaded the ZIP file from the gist, ran go build and did get:

gbbr@iMac:22580 (master)$ go build
# _/Users/gbbr/g/22580
./Goat.go:8:2: interface contains embedded non-interface Animal

@gbbr
Copy link
Member

gbbr commented Nov 6, 2017

There is some really weird behaviour going on here.

In an attempt to simplify the code to reproduce the issue, I've deleted the B.go file and now I'm getting:

# _/Users/gbbr/g/22580
./Chicken.go:8:2: interface contains embedded non-interface Animal
./Goat.go:8:2: interface contains embedded non-interface Animal

Quite an odd one. Exact reproduction steps that I've followed:

  1. Download ZIP from gist link at the top right of the page ("Download ZIP" button)
  2. Unzip in a clean folder
  3. go build

I have go1.9.2 darwin/amd64

@griesemer
Copy link
Contributor

@gbbr I cannot reproduce this. Deleting B.go is fine. The code looks valid.

I am using the latest version at tip, albeit on OS X not Windows.

@gbbr
Copy link
Member

gbbr commented Nov 6, 2017

Very odd. I've no clue why it breaks for both me and @michielvi but not you. I've even recorded a screen capture and put it on YouTube.

@mdempsky
Copy link
Member

mdempsky commented Nov 6, 2017

I cannot reproduce on Linux either. I tested at both f29f5f6882 and go1.9.2.

@michielvi @gbbr Can you include the output of "go build -x"? I'm wondering if cmd/go isn't sorting the .go files on Windows like it does on Linux / OS X.

@mdempsky
Copy link
Member

mdempsky commented Nov 6, 2017

I tried manually running the compiler (go1.9.2) with a different file ordering and discovered:

$ go tool compile A.go B.go Chicken.go Goat.go Main.go Stall.go
# ok

$ go tool compile Stall.go Goat.go Main.go Chicken.go A.go B.go
Goat.go:8:2: interface contains embedded non-interface Animal

@mdempsky
Copy link
Member

mdempsky commented Nov 6, 2017

Here's a standalone and further reduced repro case:

package p

type stall struct {
    chickens map[Chicken]bool
    goats    map[Goat]bool
}

type Stall interface {
    Chickens() map[Chicken]bool
    Goats() map[Goat]bool
}

type Goat interface {
    Animal
}

type Chicken interface {
    Animal
}

type Animal interface {
    Stall() Stall
}

@mdempsky
Copy link
Member

mdempsky commented Nov 6, 2017

The reduced repro case fails at go1.9.2, but compiles okay at tip. We must have inadvertently fixed the underlying compiler issue since then.

I'm still curious about "go build -x" output on Windows though.

@mdempsky
Copy link
Member

mdempsky commented Nov 6, 2017

It appears the compiler issue was fixed by 25159d3. (Issue still repros immediately before that CL, and no longer does after.)

@michielvi
Copy link
Author

michielvi commented Nov 6, 2017

Here is the 'go build -x' output:

WORK=C:\Users\IMMERZ~1\AppData\Local\Temp\go-build197126994
mkdir -p $WORK\test\_obj\
mkdir -p $WORK\test\_obj\exe\
cd C:\Michiel\GoWorkspace\src\test
"C:\\Michiel\\Go\\pkg\\tool\\windows_amd64\\compile.exe" -o "C:\\Users\\IMMERZ~1\\AppData\\Local\\Temp\\go-build197126994\\test.a" -trimpath "C:\\Users\\IMMERZ~1\\AppData\\Local\\Temp\\go-build197126994" -goversion go1.9.1 -p main -complete -buildid 76dcdd241d69a94171d57939527f250ad448a429 -D _/C_/Michiel/GoWorkspace/src/test -I "C:\\Users\\IMMERZ~1\\AppData\\Local\\Temp\\go-build197126994" -pack "C:\\Michiel\\GoWorkspace\\src\\test\\B.go" "C:\\Michiel\\GoWorkspace\\src\\test\\Chicken.go" "C:\\Michiel\\GoWorkspace\\src\\test\\Goat.go" "C:\\Michiel\\GoWorkspace\\src\\test\\Main.go" "C:\\Michiel\\GoWorkspace\\src\\test\\Stall.go" "C:\\Michiel\\GoWorkspace\\src\\test\\Z.go"
# test
.\Goat.go:8:2: interface contains embedded non-interface Animal

@gbbr
Copy link
Member

gbbr commented Nov 7, 2017

I can confirm that this is now fixed. It is reproducible with the 1.9.2 release but not with the tip commit.

$ go version
go version go1.9.2 darwin/amd64
$ go tool compile ./B.go ./Chicken.go ./Goat.go ./Main.go ./Stall.go ./Z.go
./Goat.go:8:2: interface contains embedded non-interface Animal
$ ~/g/go/bin/go version
go version devel +36323e4313 Tue Nov 7 01:50:16 2017 +0000 darwin/amd64
$ ~/g/go/bin/go tool compile ./B.go ./Chicken.go ./Goat.go ./Main.go ./Stall.go ./Z.go
$

Closing. Thanks @michielvi

@gbbr gbbr closed this as completed Nov 7, 2017
@michielvi
Copy link
Author

Okay, thank you all too. I am looking forward for this fix.

@golang golang locked and limited conversation to collaborators Nov 7, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants