Skip to content

cmd/compile: misleading compiler error #51233

Closed
@virtuald

Description

@virtuald

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

$ go version
go version devel go1.18-eaf0405 Wed Feb 16 21:34:51 2022 +0000 darwin/amd64

Does this issue reproduce with the latest release?

Yes

What did you do?

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

 package main
 
 type RC[RG any] interface {
 	~[]RG
 }
 
 type Fn[RCT RC[RG], RG any] func(RCT)
 
 type FFn[RCT RC[RG], RG any] func() Fn[RCT]
 
 type F[RCT RC[RG], RG any] interface {
 	Fn() Fn[RCT]
 }
 
 type concreteF[RCT RC[RG], RG any] struct {
- 	makeFn FFn[RCT]
+ 	makeFn FFn[RCT, RG]
 }
 
 func (c *concreteF[RCT, RG]) Fn() Fn[RCT] {
 	return c.makeFn()
 }
 
 func main() {}

What did you expect to see?

Nothing.

What did you see instead?

./prog.go:20:9: invalid operation: cannot call non-function c.makeFn (variable with invalid type)

If I change the line from the red version to the green version (adding the explicit type), then the compilation error disappears. I expected the compiler to figure out RG since it was part of the definition of RCT.

If type inference isn't able to figure this out, then it would be good to fix the compiler error to be less confusing. makeFn is a function, the error is actually that the compiler can't infer how to instantiate it.

Notes

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions