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

proposal: spec: automatically instantiate generic field types that are already concrete types #56726

Closed
phenpessoa opened this issue Nov 14, 2022 · 1 comment

Comments

@phenpessoa
Copy link

Currently, when you have a generic field in a struct that has a generic, but already concrete, type, to instantiate that struct you need to explicitly tell the compiler the type.

Example:

type Foo struct {
	Field Field[int]
}

type Field[T any] struct {
	Val T
}

func Bar() Foo {
	return Foo{
		Field: Field[int]{
			Val: 10,
		},
	}
}

I find Field: Field[int]{... to be redudant, because that Field can not be of any type but an int.

I propose that this would become possible:

type Foo struct {
	Field Field[int]
}

type Field[T any] struct {
	Val T
}

func Bar() Foo {
	return Foo{
		Field: Field{
			Val: 10,
		},
	}
}

Currently, this error out as cannot use generic type Field[T any] without instantiation.

@gopherbot gopherbot added this to the Proposal milestone Nov 14, 2022
@seankhliao
Copy link
Member

Duplicate of #50285

@seankhliao seankhliao marked this as a duplicate of #50285 Nov 14, 2022
@seankhliao seankhliao closed this as not planned Won't fix, can't repro, duplicate, stale Nov 14, 2022
@golang golang locked and limited conversation to collaborators Nov 14, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants