I don't know if there's much that can be done about this, but thought I'd 
mention it anyway.

Suppose you're trying to make a parameterised type, like
type Elem[T any] blah...
ex: https://go.dev/play/p/1tS1SCxTFP-

but you forget the "any", and just write
type Elem[T] blah...
ex: https://go.dev/play/p/uig7iXsgZeU

The error message, and the automatic reformatting you get, is a bit 
confusing:

type Elem [T]blah...
undeclared name T for array length

I guess this is a fundamental ambiguity in the language.  However, if an 
array length expression comes directly after a type name, *and* the array 
length itself consists of a single undeclared name, I wonder if the error 
message could give more of a hint?

undeclared name T for array length, or missing constraint for type 
parameter (e.g. "T any")

When there are multiple type parameters, it's fine:
https://go.dev/play/p/_gmrdPzoWCD

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/58763cca-622f-45d4-9c6c-9dfdbce2f623n%40googlegroups.com.

Reply via email to