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

Covariation does not work on the return value. #42307

Closed
XORveRCOM opened this issue Oct 31, 2020 · 1 comment
Closed

Covariation does not work on the return value. #42307

XORveRCOM opened this issue Oct 31, 2020 · 1 comment

Comments

@XORveRCOM
Copy link

It is inconvenient.

package main

type Sub struct {}

type ISub interface {}

type Base struct {
	sub *Sub
}

type IBase interface {
	Sub() ISub
}

func (b *Base) Sub() *Sub {
	return b.sub
}

func main() {
	var s *Sub
	s = &Sub{}
	var si ISub
	si = s
	var b IBase
	b = &Base{sub:s}
}
./prog.go:25:4: cannot use &Base literal (type *Base) as type IBase in assignment:
	*Base does not implement IBase (wrong type for Sub method)
		have Sub() *Sub
		want Sub() ISub
@mvdan
Copy link
Member

mvdan commented Oct 31, 2020

The Go project doesn't use the issue tracker for questions. See https://golang.org/wiki/Questions.

If you want to propose a language change, file a proposal issue with https://github.com/golang/proposal/blob/master/go2-language-changes.md.

@mvdan mvdan closed this as completed Oct 31, 2020
@golang golang locked and limited conversation to collaborators Oct 31, 2021
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

3 participants