Skip to content

cmd/compile: type inference fails on a case which looks simple #63750

Closed

Description

@zigo101

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

$ go version
go version go1.21.3 linux/amd64

Does this issue reproduce with the latest release?

What did you do?

package main

func foo[C ~*T | ~[]T, T any](v C) {} // compiles

func main() {
	foo(new(int))       // cannot infer T
	foo(make([]int, 3)) // cannot infer T
}

What did you expect to see?

Compiles.

What did you see instead?

Fails to compile.

Activity

  1. changed the title [-]cmd/compile: type inference failas on a case which looks simple[/-] [+]cmd/compile: type inference fails on a case which looks simple[/+] on Oct 26, 2023
  2. mauri870 commented on Oct 26, 2023

    @mauri870
    Member

    /cc @golang/compiler

  3. self-assigned this
    on Oct 26, 2023
  4. griesemer commented on Oct 26, 2023

    @griesemer
    Contributor

    Unfortunately we can't do any inference in this case because the constraint C doesn't have a core type.
    Closing because this is a known limitation of the language, not an actual bug.
    Eventually we need a concrete proposal to move forward.

  5. dr2chase commented on Oct 26, 2023

    @dr2chase
    Contributor

    This case would look simpler if it included a comment explaining what was thought to be happening.

  6. griesemer commented on Oct 26, 2023

    @griesemer
    Contributor

    @dr2chase In both cases, T should be inferred to be int.
    @go101 What we need to see to move forward with cases like these (type inference) is really good real-life examples where this matters. Functions operating on type parameters which have no core types can't do a whole lot with values of such type parameters.

  7. locked and limited conversation to collaborators on Oct 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions