]> Cypherpunks repositories - gostls13.git/commit
cmd/compile/internal/syntax: fix printing of ambiguous constraint literals
authorRobert Griesemer <gri@golang.org>
Thu, 5 May 2022 06:02:05 +0000 (23:02 -0700)
committerRobert Griesemer <gri@golang.org>
Fri, 6 May 2022 16:18:28 +0000 (16:18 +0000)
commitea6c82845589a40c35f01122ce4e2931694ffc7f
tree81c0c2a2552f5d42bff3e91dc3b4746bf2be187d
parent7f71e1fc28f03afe987881c679a925a6f7e99cac
cmd/compile/internal/syntax: fix printing of ambiguous constraint literals

Without this change, the type parameter list "[P T | T]" is printed
as "[P T | T,]" in an attempt to avoid an ambiguity. But the type
parameter P cannot syntactically combine with the constraint T | T
and make a new valid expression.

This change introduces a specific combinesWithName predicate that
reports whether a constraint expression can combine with a type
parameter name to form a new valid (value) expression.

Use combinesWithName to accurately determine when a comma is needed.

For #49482.

Change-Id: Id1d17a18f0c9af04495da7b0453e83798f32b04a
Reviewed-on: https://go-review.googlesource.com/c/go/+/404397
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
src/cmd/compile/internal/syntax/printer.go
src/cmd/compile/internal/syntax/printer_test.go