mirror of
https://github.com/golang/go
synced 2024-09-23 21:20:13 -06:00
misc/cgo/testshared: test that types and itabs are unique
Make sure that the same type and itab generated in two different shared library are actually the same thing. Change-Id: Ica45862d65ff8bc7ad04d59a41f57223f71224cd Reviewed-on: https://go-review.googlesource.com/35115 Run-TryBot: Keith Randall <khr@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
This commit is contained in:
parent
fdde7ba2a2
commit
08da8201ca
@ -815,3 +815,14 @@ func TestImplicitInclusion(t *testing.T) {
|
||||
goCmd(t, "install", "-linkshared", "implicitcmd")
|
||||
run(t, "running executable linked against library that contains same package as it", "./bin/implicitcmd")
|
||||
}
|
||||
|
||||
// Tests to make sure that the type fields of empty interfaces and itab
|
||||
// fields of nonempty interfaces are unique even across modules,
|
||||
// so that interface equality works correctly.
|
||||
func TestInterface(t *testing.T) {
|
||||
goCmd(t, "install", "-buildmode=shared", "-linkshared", "iface_a")
|
||||
// Note: iface_i gets installed implicitly as a dependency of iface_a.
|
||||
goCmd(t, "install", "-buildmode=shared", "-linkshared", "iface_b")
|
||||
goCmd(t, "install", "-linkshared", "iface")
|
||||
run(t, "running type/itab uniqueness tester", "./bin/iface")
|
||||
}
|
||||
|
17
misc/cgo/testshared/src/iface/main.go
Normal file
17
misc/cgo/testshared/src/iface/main.go
Normal file
@ -0,0 +1,17 @@
|
||||
// Copyright 2017 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package main
|
||||
|
||||
import "iface_a"
|
||||
import "iface_b"
|
||||
|
||||
func main() {
|
||||
if iface_a.F() != iface_b.F() {
|
||||
panic("empty interfaces not equal")
|
||||
}
|
||||
if iface_a.G() != iface_b.G() {
|
||||
panic("non-empty interfaces not equal")
|
||||
}
|
||||
}
|
17
misc/cgo/testshared/src/iface_a/a.go
Normal file
17
misc/cgo/testshared/src/iface_a/a.go
Normal file
@ -0,0 +1,17 @@
|
||||
// Copyright 2017 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package iface_a
|
||||
|
||||
import "iface_i"
|
||||
|
||||
//go:noinline
|
||||
func F() interface{} {
|
||||
return (*iface_i.T)(nil)
|
||||
}
|
||||
|
||||
//go:noinline
|
||||
func G() iface_i.I {
|
||||
return (*iface_i.T)(nil)
|
||||
}
|
17
misc/cgo/testshared/src/iface_b/b.go
Normal file
17
misc/cgo/testshared/src/iface_b/b.go
Normal file
@ -0,0 +1,17 @@
|
||||
// Copyright 2017 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package iface_b
|
||||
|
||||
import "iface_i"
|
||||
|
||||
//go:noinline
|
||||
func F() interface{} {
|
||||
return (*iface_i.T)(nil)
|
||||
}
|
||||
|
||||
//go:noinline
|
||||
func G() iface_i.I {
|
||||
return (*iface_i.T)(nil)
|
||||
}
|
17
misc/cgo/testshared/src/iface_i/i.go
Normal file
17
misc/cgo/testshared/src/iface_i/i.go
Normal file
@ -0,0 +1,17 @@
|
||||
// Copyright 2017 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package iface_i
|
||||
|
||||
type I interface {
|
||||
M()
|
||||
}
|
||||
|
||||
type T struct {
|
||||
}
|
||||
|
||||
func (t *T) M() {
|
||||
}
|
||||
|
||||
// *T implements I
|
Loading…
Reference in New Issue
Block a user