Skip to content

spec: typeparams: method calls do not implicitly dereference pointer-to-TypeParams #47031

Closed
@mdempsky

Description

@mdempsky

This test program exercises whether implicit dereference of pointer-to-type-parameter is allowed in a method call: https://go2goplay.golang.org/p/0C-j_EutS4c

go/types and cmd/compile/internal/types2 both accept it, but then go2go, cmd/compile -G=3, and cmd/compile unified all produce a "calling method M with receiver p (type **MyMer) requires explicit dereference" error during code generation.

A similar issue affects instantiating type parameters with interface types: https://go2goplay.golang.org/p/-vWtl3FTslw. (Here go2go and unified both report "p.M undefined (type *Mer is pointer to interface, not interface)"; -G=3 hits an assertion failure.)

What's the expected behavior here? Should go/types reject these cases as invalid, or do the compilers need to insert the implicit dereference? I don't see anything mentioned about this in the proposal.

My intuition is these are invalid, and go/types should reject them. Type parameter types act like interface types, and we don't allow implicit dereference of pointer-to-interface-type values in method calls.

/cc @griesemer @ianlancetaylor @findleyr @bcmills

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