Skip to content

go/types, types2: type inference fails if inferred type is generic function #59953

@griesemer

Description

@griesemer
package p

func _()         { f(g) }
func f[P any](P) {}
func g[Q int](Q) {}

fails to infer the instantiated type for g:

== infer : [P₃, Q₂](P₃) ➞ []
== function parameters: (P₃)
-- function arguments : [g (value of type func[Q int](Q))]
.  P₃ ≡ func[Q₂ int](Q₂)
.  P₃ ➞ func[Q₂ int](Q₂)
=> [P₃, Q₂] ➞ [func[Q₂ int](Q₂), <nil>]

== type parameters: [P₃, Q₂]
-- iteration 0
-- type parameter P₃ = func[Q₂ int](Q₂): core(P₃) = ∅, single = false
-- type parameter Q₂ = <nil>: core(Q₂) = int, single = true
Q₂ ➞ int

-- iteration 1
-- type parameter P₃ = func[Q₂ int](Q₂): core(P₃) = ∅, single = false
-- type parameter Q₂ = int: core(Q₂) = int, single = true
.  int ≡ int
=> [P₃, Q₂] ➞ [func[Q₂ int](Q₂), int]

== untyped arguments: []
=> [P₃, Q₂] ➞ [func[Q₂ int](int), int]

--- FAIL: TestManual (0.00s)
    check_test.go:164: testdata/manual.go:12:22: cannot use g (value of type func(int)) as func[Q int](int) value in argument to f

This looks like a substitution failure (type parameters are ignored) when doing substitution.

Should be fixed for 1.21 but not necessarily a release blocker as it's a somewhat esoteric case.

Metadata

Metadata

Assignees

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