Skip to content

cmd/compile: missing hint to check go.mod if language version < 1.18 and declare a generic type or func #51531

Closed
@thepudds

Description

@thepudds

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

Tip:

go version devel go1.19-63bd6f68e6 Mon Mar 7 15:02:48 2022

Does this issue reproduce with the latest release?

Yes.

What did you see?

I happened to notice a very experienced gopher this morning struggling a bit to figure out why they couldn't use generics:

I'm experimenting with generics again, with the release candidate. But now I see "type parameters require go 1.18 or later" when I try to build code with type parameters. Do I need a build flag?

Kind of a weird error to see when go version reports:
go version go1.18rc1 linux/amd64

The troubleshooting in the #generics Slack channel went back and forth a bit on whether or not the right version of Go was being used. Someone else later suggested that the go.mod language version needed to be updated, which was the issue.

I poked briefly at this using tip.

Friendly error

You get a friendly message suggesting to "check go.mod" if you instantiate a generic type or func:

type instantiation requires go1.18 or later (-lang was set to go1.17; check go.mod)

Example: https://go.dev/play/p/aXHOlSclSgT?v=gotip

Less friendly error

However, if you only declare a generic type or func without instantiation, you just get the following error (without the friendly suggestion to check go.mod):

type parameters require go1.18 or later

Example: https://go.dev/play/p/2Q1ZHdBWiPG?v=gotip


FWIW, it's clear many more gophers are going to be using generics soon 😅, and addressing this might be a small bit of polish that could avoid some toe stubbing (and perhaps head off some issues getting filed or questions on the mailing list and so on).

Obviously, someone will eventually instantiate something, but it is probably not unusual to start with a declaration first and try to compile before trying to instantiate.

Metadata

Metadata

Assignees

Labels

FrozenDueToAgeNeedsFixThe path to resolution is known, but the work has not been done.

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions