-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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
go/types: "invalid AST" error for syntactically correct (but otherwise invalid) program #25301
Comments
gp/types incorrectly assumes (and asserts) that the embedded type name denotes a defined type (or what we called a "named" type before the introduction of type aliases). |
The harder issue is that this property is exposed via the API, through the NewInterface and Embedded methods that create/access interfaces. Fixing this may require new API surface. |
PS: Both cmd/compile and gccgo accept this code: package main
type (
A = interface {
M()
}
T interface {
A
}
S struct{}
)
func (S) M() { println("m") }
func main() {
var t T = S{}
t.M()
} gccgo also accepts the example of the issue: I = interface {
m() interface{ I }
} |
Change https://golang.org/cl/114317 mentions this issue: |
@griesemer Hi, Currently tip is can’t building go-cmp package because you merged
Do you have any idea? We should fix go-cmp package? |
@zchee Can you please describe the problem you're seeing in more detail. It's a bit unclear from your message. Also, there was a bug in https://golang.org/cl/114317 which has been fixed as well. Please make sure all your code is at the latest tip. |
No no, I mean can't build https://github.com/google/go-cmp package after the merged https://golang.org/cl/114317 to tip.
OK, I'll post error logs to this thread. |
@griesemer Here is detail logs. System details
command log$ cd /path/to/go
$ git pull origin master
$ git rev-parse --verify HEAD
4fe688c6a49e59e852f0bfebbb4cf71366987ce7
$ echo $GOROOT_BOOTSTRAP
/usr/local/bootstrap/go1.4-bootstrap-20171003
$ ./make.bash -a -d -v=10 -no-banner
.
.
$ go version
go version devel +4fe688c6a4 Mon May 28 03:35:36 2018 +0000 darwin/amd64
$ go clean -cache -testcache
$ ls $GOCACHE
README log.txt trim.txt
$ rm -rf ~/go/pkg ~/go/src/github.com/google/go-cmp
$ export GOCACHE=off
$ echo $GOCACHE
off
$ go get -u -v github.com/google/go-cmp/cmp
github.com/google/go-cmp (download)
github.com/google/go-cmp/cmp/internal/diff
github.com/google/go-cmp/cmp/internal/function
github.com/google/go-cmp/cmp/internal/value
github.com/google/go-cmp/cmp
$ cd ~/go/src/github.com/google/go-cmp
$ git rev-parse --verify HEAD
5411ab924f9ffa6566244a9e504bc347edacffd3
$ cd /path/to/sandbox
$ cat cmp_test.go
package cmp_test
import (
"testing"
"github.com/google/go-cmp/cmp"
)
type testType struct {
Prop string
}
func TestGoCmp(t *testing.T) {
foo := testType{
Prop: "foo prop",
}
bar := testType{
Prop: "bar prop",
}
if diff := cmp.Diff(foo, bar); diff != "" {
t.Fatalf("(-got, +want)\n%s", diff)
}
} $ go test -v -x .
WORK=/var/folders/mq/m9_twy8j1vl9ppr6j5xqtfq80000gn/T/go-build547930116
mkdir -p $WORK/b001/
mkdir -p $WORK/b050/
cat >$WORK/b050/importcfg << 'EOF' # internal
# import config
EOF
cd /Users/zchee/go/src/github.com/google/go-cmp/cmp/internal/diff
/usr/local/go/pkg/tool/darwin_amd64/compile -o $WORK/b050/_pkg_.a -trimpath $WORK/b050 -p github.com/google/go-cmp/cmp/internal/diff -complete -buildid 4_AW8SL18On6OPJD_vCg/4_AW8SL18On6OPJD_vCg -D "" -importcfg $WORK/b050/importcfg -pack -c=4 ./debug_disable.go ./diff.go
/usr/local/go/pkg/tool/darwin_amd64/buildid -w $WORK/b050/_pkg_.a # internal
mkdir -p $WORK/b051/
cat >$WORK/b051/importcfg << 'EOF' # internal
# import config
packagefile reflect=/usr/local/go/pkg/darwin_amd64/reflect.a
EOF
cd /Users/zchee/go/src/github.com/google/go-cmp/cmp/internal/function
/usr/local/go/pkg/tool/darwin_amd64/compile -o $WORK/b051/_pkg_.a -trimpath $WORK/b051 -p github.com/google/go-cmp/cmp/internal/function -complete -buildid 27DKHZmYO-qdKgzox5Nb/27DKHZmYO-qdKgzox5Nb -D "" -importcfg $WORK/b051/importcfg -pack -c=4 ./func.go
mkdir -p $WORK/b052/
cat >$WORK/b052/importcfg << 'EOF' # internal
# import config
packagefile fmt=/usr/local/go/pkg/darwin_amd64/fmt.a
packagefile math=/usr/local/go/pkg/darwin_amd64/math.a
packagefile reflect=/usr/local/go/pkg/darwin_amd64/reflect.a
packagefile sort=/usr/local/go/pkg/darwin_amd64/sort.a
packagefile strconv=/usr/local/go/pkg/darwin_amd64/strconv.a
packagefile strings=/usr/local/go/pkg/darwin_amd64/strings.a
packagefile unicode=/usr/local/go/pkg/darwin_amd64/unicode.a
EOF
cd /Users/zchee/go/src/github.com/google/go-cmp/cmp/internal/value
/usr/local/go/pkg/tool/darwin_amd64/compile -o $WORK/b052/_pkg_.a -trimpath $WORK/b052 -p github.com/google/go-cmp/cmp/internal/value -complete -buildid rXYevHN1CWvfekjBHhuN/rXYevHN1CWvfekjBHhuN -D "" -importcfg $WORK/b052/importcfg -pack -c=4 ./format.go ./pointer_unsafe.go ./sort.go
/usr/local/go/pkg/tool/darwin_amd64/buildid -w $WORK/b051/_pkg_.a # internal
/usr/local/go/pkg/tool/darwin_amd64/buildid -w $WORK/b052/_pkg_.a # internal
mkdir -p $WORK/b049/
cat >$WORK/b049/importcfg << 'EOF' # internal
# import config
packagefile fmt=/usr/local/go/pkg/darwin_amd64/fmt.a
packagefile github.com/google/go-cmp/cmp/internal/diff=$WORK/b050/_pkg_.a
packagefile github.com/google/go-cmp/cmp/internal/function=$WORK/b051/_pkg_.a
packagefile github.com/google/go-cmp/cmp/internal/value=$WORK/b052/_pkg_.a
packagefile reflect=/usr/local/go/pkg/darwin_amd64/reflect.a
packagefile runtime=/usr/local/go/pkg/darwin_amd64/runtime.a
packagefile strings=/usr/local/go/pkg/darwin_amd64/strings.a
packagefile unicode=/usr/local/go/pkg/darwin_amd64/unicode.a
packagefile unicode/utf8=/usr/local/go/pkg/darwin_amd64/unicode/utf8.a
EOF
cd /Users/zchee/go/src/github.com/google/go-cmp/cmp
/usr/local/go/pkg/tool/darwin_amd64/compile -o $WORK/b049/_pkg_.a -trimpath $WORK/b049 -p github.com/google/go-cmp/cmp -complete -buildid WUnxqFCUSEMWrlZSWCoY/WUnxqFCUSEMWrlZSWCoY -D "" -importcfg $WORK/b049/importcfg -pack -c=4 ./compare.go ./options.go ./path.go ./reporter.go ./unsafe_reflect.go
/usr/local/go/pkg/tool/darwin_amd64/buildid -w $WORK/b049/_pkg_.a # internal
mkdir -p $WORK/b048/
cat >$WORK/b048/importcfg << 'EOF' # internal
# import config
packagefile github.com/google/go-cmp/cmp=$WORK/b049/_pkg_.a
packagefile testing=/usr/local/go/pkg/darwin_amd64/testing.a
EOF
cd /Users/zchee/go/src/github.com/zchee/go-sandbox/go-cmp
/usr/local/go/pkg/tool/darwin_amd64/compile -o $WORK/b048/_pkg_.a -trimpath $WORK/b048 -p github.com/zchee/go-sandbox/go-cmp_test -complete -buildid 7U1xJTO3_lNC60A4mnG_/7U1xJTO3_lNC60A4mnG_ -D "" -importcfg $WORK/b048/importcfg -pack -c=4 ./cmp_test.go
/usr/local/go/pkg/tool/darwin_amd64/buildid -w $WORK/b048/_pkg_.a # internal
cat >$WORK/b001/importcfg << 'EOF' # internal
# import config
packagefile os=/usr/local/go/pkg/darwin_amd64/os.a
packagefile testing=/usr/local/go/pkg/darwin_amd64/testing.a
packagefile testing/internal/testdeps=/usr/local/go/pkg/darwin_amd64/testing/internal/testdeps.a
packagefile runtime=/usr/local/go/pkg/darwin_amd64/runtime.a
packagefile github.com/zchee/go-sandbox/go-cmp_test=$WORK/b048/_pkg_.a
EOF
cd $WORK/b001/
/usr/local/go/pkg/tool/darwin_amd64/compile -o ./_pkg_.a -trimpath $WORK/b001 -p main -complete -buildid pdJgXbRKe6CnEPamwzsd/pdJgXbRKe6CnEPamwzsd -dwarf=false -D "" -importcfg ./importcfg -pack -c=4 ./_testmain.go
cat >$WORK/b048/vet.cfg << 'EOF' # internal
{
"Compiler": "gc",
"Dir": "/Users/zchee/go/src/github.com/zchee/go-sandbox/go-cmp",
"GoFiles": [
"/Users/zchee/go/src/github.com/zchee/go-sandbox/go-cmp/cmp_test.go"
],
"ImportMap": {
"fmt": "fmt",
"github.com/google/go-cmp/cmp": "github.com/google/go-cmp/cmp",
"testing": "testing"
},
"PackageFile": {
"fmt": "/usr/local/go/pkg/darwin_amd64/fmt.a",
"github.com/google/go-cmp/cmp": "$WORK/b049/_pkg_.a",
"testing": "/usr/local/go/pkg/darwin_amd64/testing.a"
},
"Standard": {
"fmt": true,
"testing": true
},
"ImportPath": "github.com/zchee/go-sandbox/go-cmp_test",
"SucceedOnTypecheckFailure": false
}
EOF
cd /Users/zchee/go/src/github.com/zchee/go-sandbox/go-cmp
/usr/local/go/pkg/tool/darwin_amd64/vet -atomic -bool -buildtags -nilfunc -printf $WORK/b048/vet.cfg
/usr/local/go/pkg/tool/darwin_amd64/buildid -w $WORK/b001/_pkg_.a # internal
# github.com/zchee/go-sandbox/go-cmp_test
./cmp_test.go:6:2: could not import github.com/google/go-cmp/cmp (cannot import, possibly version skew (embedded type is not an interface) - reinstall package)
vet: typecheck failures
cat >$WORK/b001/importcfg.link << 'EOF' # internal
packagefile github.com/zchee/go-sandbox/go-cmp.test=$WORK/b001/_pkg_.a
packagefile os=/usr/local/go/pkg/darwin_amd64/os.a
packagefile testing=/usr/local/go/pkg/darwin_amd64/testing.a
packagefile testing/internal/testdeps=/usr/local/go/pkg/darwin_amd64/testing/internal/testdeps.a
packagefile runtime=/usr/local/go/pkg/darwin_amd64/runtime.a
packagefile github.com/zchee/go-sandbox/go-cmp_test=$WORK/b048/_pkg_.a
packagefile errors=/usr/local/go/pkg/darwin_amd64/errors.a
packagefile internal/poll=/usr/local/go/pkg/darwin_amd64/internal/poll.a
packagefile internal/syscall/unix=/usr/local/go/pkg/darwin_amd64/internal/syscall/unix.a
packagefile internal/testlog=/usr/local/go/pkg/darwin_amd64/internal/testlog.a
packagefile io=/usr/local/go/pkg/darwin_amd64/io.a
packagefile sync=/usr/local/go/pkg/darwin_amd64/sync.a
packagefile sync/atomic=/usr/local/go/pkg/darwin_amd64/sync/atomic.a
packagefile syscall=/usr/local/go/pkg/darwin_amd64/syscall.a
packagefile time=/usr/local/go/pkg/darwin_amd64/time.a
packagefile bytes=/usr/local/go/pkg/darwin_amd64/bytes.a
packagefile flag=/usr/local/go/pkg/darwin_amd64/flag.a
packagefile fmt=/usr/local/go/pkg/darwin_amd64/fmt.a
packagefile internal/race=/usr/local/go/pkg/darwin_amd64/internal/race.a
packagefile runtime/debug=/usr/local/go/pkg/darwin_amd64/runtime/debug.a
packagefile runtime/trace=/usr/local/go/pkg/darwin_amd64/runtime/trace.a
packagefile sort=/usr/local/go/pkg/darwin_amd64/sort.a
packagefile strconv=/usr/local/go/pkg/darwin_amd64/strconv.a
packagefile strings=/usr/local/go/pkg/darwin_amd64/strings.a
packagefile bufio=/usr/local/go/pkg/darwin_amd64/bufio.a
packagefile regexp=/usr/local/go/pkg/darwin_amd64/regexp.a
packagefile runtime/pprof=/usr/local/go/pkg/darwin_amd64/runtime/pprof.a
packagefile internal/bytealg=/usr/local/go/pkg/darwin_amd64/internal/bytealg.a
packagefile internal/cpu=/usr/local/go/pkg/darwin_amd64/internal/cpu.a
packagefile runtime/internal/atomic=/usr/local/go/pkg/darwin_amd64/runtime/internal/atomic.a
packagefile runtime/internal/sys=/usr/local/go/pkg/darwin_amd64/runtime/internal/sys.a
packagefile github.com/google/go-cmp/cmp=$WORK/b049/_pkg_.a
packagefile unicode=/usr/local/go/pkg/darwin_amd64/unicode.a
packagefile unicode/utf8=/usr/local/go/pkg/darwin_amd64/unicode/utf8.a
packagefile reflect=/usr/local/go/pkg/darwin_amd64/reflect.a
packagefile math=/usr/local/go/pkg/darwin_amd64/math.a
packagefile context=/usr/local/go/pkg/darwin_amd64/context.a
packagefile math/bits=/usr/local/go/pkg/darwin_amd64/math/bits.a
packagefile regexp/syntax=/usr/local/go/pkg/darwin_amd64/regexp/syntax.a
packagefile compress/gzip=/usr/local/go/pkg/darwin_amd64/compress/gzip.a
packagefile encoding/binary=/usr/local/go/pkg/darwin_amd64/encoding/binary.a
packagefile io/ioutil=/usr/local/go/pkg/darwin_amd64/io/ioutil.a
packagefile text/tabwriter=/usr/local/go/pkg/darwin_amd64/text/tabwriter.a
packagefile github.com/google/go-cmp/cmp/internal/diff=$WORK/b050/_pkg_.a
packagefile github.com/google/go-cmp/cmp/internal/function=$WORK/b051/_pkg_.a
packagefile github.com/google/go-cmp/cmp/internal/value=$WORK/b052/_pkg_.a
packagefile compress/flate=/usr/local/go/pkg/darwin_amd64/compress/flate.a
packagefile hash/crc32=/usr/local/go/pkg/darwin_amd64/hash/crc32.a
packagefile path/filepath=/usr/local/go/pkg/darwin_amd64/path/filepath.a
packagefile hash=/usr/local/go/pkg/darwin_amd64/hash.a
EOF
cd .
/usr/local/go/pkg/tool/darwin_amd64/link -o $WORK/b001/go-cmp.test -importcfg $WORK/b001/importcfg.link -s -w -buildmode=exe -buildid=xF9VDmxotIV5MF7WaAGS/pdJgXbRKe6CnEPamwzsd/EQp1yh7RMcJq6CdhoP-L/xF9VDmxotIV5MF7WaAGS -extld=/Applications/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang $WORK/b001/_pkg_.a
rm -r $WORK/b001/
FAIL github.com/zchee/go-sandbox/go-cmp [build failed] actual error log./cmp_test.go:6:2: could not import github.com/google/go-cmp/cmp (cannot import, possibly version skew (embedded type is not an interface) - reinstall package)
vet: typecheck failures on go1.10.2$ go version
go version go1.10.2 darwin/amd64
$ go test -v -run=. .
=== RUN TestGoCmp
--- FAIL: TestGoCmp (0.00s)
cmp_test.go:23: (-got, +want)
{cmp_test.testType}.Prop:
-: "foo prop"
+: "bar prop"
FAIL
FAIL github.com/zchee/go-sandbox/go-cmp 0.007s Should I create new issue thread? If so, golang/go or google/go-cmp, which is the correct repo to create an issue thread? |
I can reproduce it now. I will look into it. No need for further action from your side. |
Filed #25615. |
Change https://golang.org/cl/115155 mentions this issue: |
In https://go-review.googlesource.com/c/go/+/114317 (fix for #25301) the constructor types.NewInterface was replaced with NewInterface2. The new constructor aggressively verified that embedded interfaces had an underlying type of interface type; the old code didn't do any verification. During importing, defined types may be not yet fully set up, and testing their underlying types will fail in those cases. This change only verifies embedded types that are not defined types and thus restores behavior for defined types to how it was before the fix for #25301. Fixes #25596. Fixes #25615. Change-Id: Ifd694413656ec0b780fe4f37acaa9e6ba6077271 Reviewed-on: https://go-review.googlesource.com/115155 Run-TryBot: Robert Griesemer <gri@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Alan Donovan <adonovan@google.com>
Change https://golang.org/cl/118555 mentions this issue: |
…n in std lib This CL brings over the changes from: https://go-review.googlesource.com/118496 (better error message when importer is out of date) https://go-review.googlesource.com/114317 (permit embedding of non-defined interfaces via alias type names) https://go-review.googlesource.com/85318 (use named receiver types for methods of named interfaces) https://go-review.googlesource.com/42870 (report import path if package is not found) https://go-review.googlesource.com/41710 (version tests for 1.8, v4 and v5) Also updated go/gcexportdata to select between binary and new indexed export format. For golang/go#25856. For golang/go#25301. For golang/go#20230. For golang/go#13829. Change-Id: Ibf77c50f86e767cef411bd1d3809e12397678958 Reviewed-on: https://go-review.googlesource.com/118555 Run-TryBot: Robert Griesemer <gri@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Alan Donovan <adonovan@google.com>
Change https://golang.org/cl/120875 mentions this issue: |
Change https://golang.org/cl/120895 mentions this issue: |
NewInterface2 was introduced with https://go-review.googlesource.com/114317 which fixed #25301. Changed the name to NewInterfaceType to better match Go naming styles, per discussion with @josharian, @iant, et al. Change-Id: Ifa4708a5efd4f708295b33c3d20fdc5812e1b4fc Reviewed-on: https://go-review.googlesource.com/120875 Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com> Reviewed-by: Ian Lance Taylor <iant@golang.org>
https://go-review.googlesource.com/c/go/+/120875 changed the name of types.NewInterface2 to NewInterfaceType. Adjust x/tools code to match new API. For golang/go#25301. Change-Id: I21e13566f7c88591a16ce461cb4cce8901980b05 Reviewed-on: https://go-review.googlesource.com/120895 Run-TryBot: Robert Griesemer <gri@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com> Reviewed-by: Ian Lance Taylor <iant@golang.org>
x.go:
gotype x.go produces
For reference:
cmd.compile:
gccgo accepts this code w/o error.
The text was updated successfully, but these errors were encountered: