Skip to content

go/types: self-reference within type parameter constraints #46461

Closed
@mdempsky

Description

@mdempsky

This test case sends go/types into an infinite recursion: https://go2goplay.golang.org/p/fpWup_pjUzi

type T[U interface{ M() T }] int

type X int
func (X) M() T[X] { return 0 }

Two questions:

  1. Are recursive type parameters like this supposed to work? If so, this has implications on extending the go/types API and export data format to support type parameters (e.g., see also proposal: go/types: lazy resolution of imported objects #46449 (comment)).

  2. Also if so, shouldn't interface{ M() T } actually be interface{ M() T[U] }? However, go/types explicitly rejects the latter.

/cc @griesemer @ianlancetaylor @findleyr @bcmills

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions