Skip to content

Commit

Permalink
cmd/compile/internal/syntax: remove AllowTypeSets mode
Browse files Browse the repository at this point in the history
The respective issue has been accepted, so we can always
accept constraint literals with omitted interfaces.

For #48424.

Change-Id: Ia3d325401252a5a22d5ffa98d2ae6af73178dec0
Reviewed-on: https://go-review.googlesource.com/c/go/+/355709
Trust: Robert Griesemer <gri@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
  • Loading branch information
griesemer committed Oct 14, 2021
1 parent b90d258 commit 276fb27
Show file tree
Hide file tree
Showing 7 changed files with 9 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/cmd/compile/internal/noder/noder.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func LoadPackage(filenames []string) {

mode := syntax.CheckBranches
if supportsGenerics {
mode |= syntax.AllowGenerics | syntax.AllowTypeSets
mode |= syntax.AllowGenerics
}

// Limit the number of simultaneously open files.
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/compile/internal/syntax/error_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ func testSyntaxErrors(t *testing.T, filename string) {

var mode Mode
if strings.HasSuffix(filename, ".go2") {
mode = AllowGenerics | AllowTypeSets
mode = AllowGenerics
}
ParseFile(filename, func(err error) {
e, ok := err.(Error)
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/compile/internal/syntax/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -1820,7 +1820,7 @@ func (p *parser) paramDeclOrNil(name *Name, follow token) *Field {
}

// type set notation is ok in type parameter lists
typeSetsOk := p.mode&AllowTypeSets != 0 && follow == _Rbrack
typeSetsOk := follow == _Rbrack

pos := p.pos()
if name != nil {
Expand Down
6 changes: 3 additions & 3 deletions src/cmd/compile/internal/syntax/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ var (
)

func TestParse(t *testing.T) {
ParseFile(*src_, func(err error) { t.Error(err) }, nil, AllowGenerics|AllowTypeSets)
ParseFile(*src_, func(err error) { t.Error(err) }, nil, AllowGenerics)
}

func TestVerify(t *testing.T) {
ast, err := ParseFile(*src_, func(err error) { t.Error(err) }, nil, AllowGenerics|AllowTypeSets)
ast, err := ParseFile(*src_, func(err error) { t.Error(err) }, nil, AllowGenerics)
if err != nil {
return // error already reported
}
Expand All @@ -46,7 +46,7 @@ func TestParseGo2(t *testing.T) {
for _, fi := range list {
name := fi.Name()
if !fi.IsDir() && !strings.HasPrefix(name, ".") {
ParseFile(filepath.Join(dir, name), func(err error) { t.Error(err) }, nil, AllowGenerics|AllowTypeSets)
ParseFile(filepath.Join(dir, name), func(err error) { t.Error(err) }, nil, AllowGenerics)
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/cmd/compile/internal/syntax/printer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ var stringTests = []string{
"package p; func (*R[A, B, C]) _()",
"package p; func (_ *R[A, B, C]) _()",

// type constraint literals with elided interfaces (only if AllowTypeSets is set)
// type constraint literals with elided interfaces
"package p; func _[P ~int, Q int | string]() {}",
"package p; func _[P struct{f int}, Q *P]() {}",

Expand All @@ -94,7 +94,7 @@ var stringTests = []string{

func TestPrintString(t *testing.T) {
for _, want := range stringTests {
ast, err := Parse(nil, strings.NewReader(want), nil, nil, AllowGenerics|AllowTypeSets)
ast, err := Parse(nil, strings.NewReader(want), nil, nil, AllowGenerics)
if err != nil {
t.Error(err)
continue
Expand Down
1 change: 0 additions & 1 deletion src/cmd/compile/internal/syntax/syntax.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ type Mode uint
const (
CheckBranches Mode = 1 << iota // check correct use of labels, break, continue, and goto statements
AllowGenerics
AllowTypeSets // requires AllowGenerics; remove once #48424 is decided
)

// Error describes a syntax error. Error implements the error interface.
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/compile/internal/types2/check_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func testFiles(t *testing.T, filenames []string, colDelta uint, manual bool) {

var mode syntax.Mode
if strings.HasSuffix(filenames[0], ".go2") {
mode |= syntax.AllowGenerics | syntax.AllowTypeSets
mode |= syntax.AllowGenerics
}
// parse files and collect parser errors
files, errlist := parseFiles(t, filenames, mode)
Expand Down

0 comments on commit 276fb27

Please sign in to comment.