You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
typeBase[Tany] struct {
CustomT
}
func (b*Base[T]) Show() {
fmt.Println("Hi, Septem")
}
func (b*Base[int]) Call() {
fmt.Println("Hi, Septem??")
}
funcmain() {
f:=&Base[float64]{}
// I don't expect it could be compiled. The type of `f` is `*Base[float64]` rather than `*Base[int]`f.Call()
}
typeBase[Tany] struct {
CustomT
}
func (b*Base[T]) Show() {
fmt.Println("Hi, Septem")
}
func (b*Base[int]) ReturnInt() int {
return123
}
funcmain() {
f:=&Base[int]{}
// I expected it could be compiled.f.ReturnInt()
}
What did you expect to see?
First case shouldn't be compiled, and the second case could be compiled.
What did you see instead?
First case passed.
Second one failed, and show the following message: cannot use 123 (untyped int constant) as int /* with int declared at ./main.go:65:15 */ value in return statement
I'm not pretty sure do we allow this syntax (e.g. Base[int] as receiver in the case) or not.
But if we don't, both of these cases should failed.
The text was updated successfully, but these errors were encountered:
septemhill
changed the title
cmd/compile: specific type for generic struct type
cmd/compile: specific type for generic struct type in recevier
Aug 15, 2023
Uh oh!
There was an error while loading. Please reload this page.
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes.
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
First case: https://go.dev/play/p/B1k27y3z0OQ
Second case: https://go.dev/play/p/IHQyecfPsL3
What did you expect to see?
First case shouldn't be compiled, and the second case could be compiled.
What did you see instead?
First case passed.
Second one failed, and show the following message:
cannot use 123 (untyped int constant) as int /* with int declared at ./main.go:65:15 */ value in return statement
I'm not pretty sure do we allow this syntax (e.g.
Base[int]
as receiver in the case) or not.But if we don't, both of these cases should failed.
The text was updated successfully, but these errors were encountered: