Skip to content

go/types, types2: does not see duplicate methods #67582

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

Closed
AlphaHot opened this issue May 22, 2024 · 3 comments
Closed

go/types, types2: does not see duplicate methods #67582

AlphaHot opened this issue May 22, 2024 · 3 comments

Comments

@AlphaHot
Copy link

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

$ go version
go version go1.22.2 linux/amd64

Does this issue reproduce with the latest release?

Yes

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

go env Output
$ go env
GO111MODULE=''
GOARCH='amd64'
GOBIN=''
GOCACHE='/home/AlphaHot/.cache/go-build'
GOENV='/home/AlphaHot/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMODCACHE='/home/AlphaHot/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='linux'
GOPATH='/home/AlphaHot/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/usr/local/go'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/usr/local/go/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='go1.22.2'
GCCGO='gccgo'
GOAMD64='v1'
AR='ar'
CC='gcc'
CXX='g++'
CGO_ENABLED='1'
GOMOD='/home/AlphaHot/lg/go.mod'
GOWORK=''
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build149263860=/tmp/go-build -gno-record-gcc-switches'
uname -sr: Linux 4.18.0-26-generic
Distributor ID:	Ubuntu
Description:	Ubuntu 18.10
Release:	18.10
Codename:	cosmic
/lib/x86_64-linux-gnu/libc.so.6: GNU C Library (Ubuntu GLIBC 2.28-0ubuntu1) stable release version 2.28.
gdb --version: GNU gdb (Ubuntu 8.2-0ubuntu1) 8.2

What did you do?

https://go.dev/play/p/esbx12UNVzc?v=gotip

What did you expect to see?

./prog.go:14:3: duplicate method `a'
	./prog.go:13:3: other declaration of `a'

What did you see instead?

:/
@zigo101
Copy link

zigo101 commented May 23, 2024

This is allowed, as long as the duplicated methods have the identical signature.

You can even embed a type in an interface type for multiple times:

type (
	TINTERa interface {
		a() string
		TINTERb
		TINTERb
		TINTERb
		TINTERb
		TINTERb
	}
	TINTERb interface {
		a() string
	}
)

@AlphaHot
Copy link
Author

@go101 why is this allowed?

@dominikh
Copy link
Member

Consider from https://go.dev/ref/spec#Embedded_interfaces:

type Reader interface {
	Read(p []byte) (n int, err error)
	Close() error
}

type Writer interface {
	Write(p []byte) (n int, err error)
	Close() error
}

// ReadWriter's methods are Read, Write, and Close.
type ReadWriter interface {
	Reader  // includes methods of Reader in ReadWriter's method set
	Writer  // includes methods of Writer in ReadWriter's method set
}

@dominikh dominikh closed this as not planned Won't fix, can't repro, duplicate, stale May 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants