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

cmd/compile: "methods cannot have type parameters" compiler error reported twice #50317

Closed
ilya-zz opened this issue Dec 22, 2021 · 3 comments
Closed
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@ilya-zz
Copy link

ilya-zz commented Dec 22, 2021

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

$ go version
devel go1.18-90fb5a4f97 Wed Dec 22 00:11:21 2021 +0000

Does this issue reproduce with the latest release?

What operating system and processor architecture are you using (go env)?

go env Output
$ go env

What did you do?

https://gotipplay.golang.org/p/-LsXizeqqJK

package main

import (
	"fmt"
)

type Foo[T any] struct {
	t T
}

func (f Foo[T]) Do[T any] () {
	fmt.Println(f.t)
}

What did you expect to see?

The methods cannot have type parameters compiler error

What did you see instead?

./prog.go:11:19: methods cannot have type parameters
./prog.go:11:20: invalid AST: method must have no type parameters
./prog.go:11:20: T redeclared in this block
	prog.go:11:13: other declaration of T

Not a big deal, but it probably would be a better DX to report methods cannot have type parameters only once.

@ianlancetaylor ianlancetaylor added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Dec 22, 2021
@ianlancetaylor ianlancetaylor added this to the Go1.18 milestone Dec 22, 2021
@ianlancetaylor
Copy link
Contributor

CC @griesemer @findleyr

Thanks. Marking for 1.18 but not a release blocker.

@griesemer griesemer self-assigned this Jan 6, 2022
@gopherbot
Copy link

Change https://golang.org/cl/376054 mentions this issue: cmd/compile: report type parameter error for methods only once

@gopherbot
Copy link

Change https://golang.org/cl/376215 mentions this issue: test/typeparam: adjust test preamble (fix longtests)

gopherbot pushed a commit that referenced this issue Jan 7, 2022
For #50317.

Change-Id: I24ccf333c380283a36b573ef8fc3e7fcd71bd17f
Reviewed-on: https://go-review.googlesource.com/c/go/+/376215
Trust: Robert Griesemer <gri@golang.org>
Run-TryBot: Robert Griesemer <gri@golang.org>
Reviewed-by: Dan Scales <danscales@google.com>
Trust: Dan Scales <danscales@google.com>
jproberts pushed a commit to jproberts/go that referenced this issue Jun 21, 2022
Move switch to enable method type parameters entirely
to the parser, by adding the mode AllowMethodTypeParams.
Ensure that the error messages are consistent.
Remove unnecessary code in the type checker.

Fixes golang#50317.

Change-Id: I4f3958722400bdb919efa4c494b85cf62f4002bb
Reviewed-on: https://go-review.googlesource.com/c/go/+/376054
Trust: Robert Griesemer <gri@golang.org>
Run-TryBot: Robert Griesemer <gri@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
jproberts pushed a commit to jproberts/go that referenced this issue Jun 21, 2022
For golang#50317.

Change-Id: I24ccf333c380283a36b573ef8fc3e7fcd71bd17f
Reviewed-on: https://go-review.googlesource.com/c/go/+/376215
Trust: Robert Griesemer <gri@golang.org>
Run-TryBot: Robert Griesemer <gri@golang.org>
Reviewed-by: Dan Scales <danscales@google.com>
Trust: Dan Scales <danscales@google.com>
@golang golang locked and limited conversation to collaborators Jun 22, 2023
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

4 participants