]> Cypherpunks.ru repositories - gostls13.git/commit
cmd/compile/internal/syntax: better error messages for incorrect type parameter list
authorRobert Griesemer <gri@golang.org>
Tue, 31 Oct 2023 20:29:25 +0000 (13:29 -0700)
committerGopher Robot <gobot@golang.org>
Wed, 1 Nov 2023 17:49:03 +0000 (17:49 +0000)
commitb7a695bd684585a86ae883c64eb8cfc2b80d847b
tree30e50640d13a475971274dd6814541f695720887
parent34a5830c267e76bdcf1f1aa6725f140af2e82f62
cmd/compile/internal/syntax: better error messages for incorrect type parameter list

When parsing a declaration of the form

        type a [b[c]]d

where a, b, c, d stand for identifiers, b[c] is parsed as a type
constraint (because an array length must be constant and an index
expression b[c] is never constant, even if b is a constant string
and c a constant index - this is crucial for disambiguation of the
various possibilities).

As a result, the error message referred to a missing type parameter
name and not an invalid array declaration.

Recognize this special case and report both possibilities (because
we can't be sure without type information) with the new error:

       "missing type parameter name or invalid array length"

ALso, change the previous error message

        "type parameter must be named"

to

        "missing type parameter name"

which is more fitting as the error refers to an absent type parameter
(rather than a type parameter that's somehow invisibly present but
unnamed).

Fixes #60812.

Change-Id: Iaad3b3a9aeff9dfe2184779f3d799f16c7500b34
Reviewed-on: https://go-review.googlesource.com/c/go/+/538856
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Robert Griesemer <gri@google.com>
Reviewed-by: Robert Griesemer <gri@google.com>
Auto-Submit: Robert Griesemer <gri@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
src/cmd/compile/internal/syntax/parser.go
src/cmd/compile/internal/syntax/testdata/issue43527.go
src/cmd/compile/internal/syntax/testdata/tparams.go
src/cmd/compile/internal/syntax/testdata/typeset.go