Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
griesemer opened this issue May 3, 2023 · 1 comment
Closed
Assignees
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@griesemer
Copy link
Contributor

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.

@griesemer griesemer added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label May 3, 2023
@griesemer griesemer added this to the Go1.21 milestone May 3, 2023
@griesemer griesemer self-assigned this May 3, 2023
@gopherbot
Copy link
Contributor

Change https://go.dev/cl/491797 mentions this issue: go/types, types2: consider generic functions in inference simplify step

@golang golang locked and limited conversation to collaborators May 3, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

2 participants