From 700920bbb73b39af4794854e79b76dc9b66b19ca Mon Sep 17 00:00:00 2001 From: Mateusz Poliwczak Date: Mon, 2 Sep 2024 12:37:51 +0000 Subject: [PATCH] go/printer: do not panic on *ast.ParenExpr in combinesWithName Fixes #69206 Change-Id: I1b5a664c22d5739e2c6748d562591f57345b536e GitHub-Last-Rev: 1798e2c65b3c2c0c1ef674b000dce2636c834783 GitHub-Pull-Request: golang/go#69208 Reviewed-on: https://go-review.googlesource.com/c/go/+/610115 Reviewed-by: Robert Griesemer LUCI-TryBot-Result: Go LUCI Auto-Submit: Robert Griesemer Reviewed-by: Dmitri Shuralyov --- src/go/printer/nodes.go | 4 +--- src/go/printer/testdata/generics.golden | 2 ++ src/go/printer/testdata/generics.input | 2 ++ 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/go/printer/nodes.go b/src/go/printer/nodes.go index a4651e0608..495ec22031 100644 --- a/src/go/printer/nodes.go +++ b/src/go/printer/nodes.go @@ -411,9 +411,7 @@ func combinesWithName(x ast.Expr) bool { case *ast.BinaryExpr: return combinesWithName(x.X) && !isTypeElem(x.Y) case *ast.ParenExpr: - // name(x) combines but we are making sure at - // the call site that x is never parenthesized. - panic("unexpected parenthesized expression") + return combinesWithName(x.X) } return false } diff --git a/src/go/printer/testdata/generics.golden b/src/go/printer/testdata/generics.golden index 7ddf20b3d1..89f5b88dbf 100644 --- a/src/go/printer/testdata/generics.golden +++ b/src/go/printer/testdata/generics.golden @@ -45,6 +45,8 @@ type _[P T | T] struct{} type _[P T | T | T | T] struct{} type _[P *T, _ any] struct{} type _[P *T,] struct{} +type _[P *T,] struct{} +type _[P ~int] struct{} type _[P *T, _ any] struct{} type _[P T] struct{} type _[P T, _ any] struct{} diff --git a/src/go/printer/testdata/generics.input b/src/go/printer/testdata/generics.input index 4940f9319a..bc24119c2e 100644 --- a/src/go/printer/testdata/generics.input +++ b/src/go/printer/testdata/generics.input @@ -42,6 +42,8 @@ type _[P T | T] struct{} type _[P T | T | T | T] struct{} type _[P *T, _ any] struct{} type _[P (*T),] struct{} +type _[P ((*T)),] struct{} +type _[P ((~int)),] struct{} type _[P (*T), _ any] struct{} type _[P (T),] struct{} type _[P (T), _ any] struct{} -- 2.48.1