Fix #78006: include type arguments in instantiated type cycle errors#78009
Fix #78006: include type arguments in instantiated type cycle errors#780099chait9 wants to merge 1 commit intogolang:masterfrom
Conversation
|
This PR (HEAD: 89839d1) has been imported to Gerrit for code review. Please visit Gerrit at https://go-review.googlesource.com/c/go/+/752660. Important tips:
|
|
Message from Gopher Robot: Patch Set 1: (1 comment) Please don’t reply on this GitHub thread. Visit golang.org/cl/752660. |
|
Message from Gopher Robot: Patch Set 1: Congratulations on opening your first change. Thank you for your contribution! Next steps: Most changes in the Go project go through a few rounds of revision. This can be During May-July and Nov-Jan the Go project is in a code freeze, during which Please don’t reply on this GitHub thread. Visit golang.org/cl/752660. |
More Context
This PR addresses issue #78006 by enhancing the clarity of cycle error messages for instantiated generic types in the Go compiler. Previously, when a declaration cycle involved a generic type instantiated with specific arguments (e.g.,
MyType[int]), the compiler's error message would only display the generic type's base name ("MyType"), omitting the crucial type arguments. This made it challenging to identify the exact recursive type causing the error.The core problem lies in the
pathStringfunction and the localnamehelper withinsrc/cmd/compile/internal/types2/decl.go. These functions, responsible for constructing cycle error messages, did not leverage the full type-formatting capabilities available insrc/cmd/compile/internal/types2/typestring.go. Consequently, when processing anObjectrepresenting an instantiated genericTypeName,obj.Name()only returned the base name, ignoring the associated type arguments. This PR rectifies this by integrating the detailed type representation fromtypestring.gointo the error reporting indecl.go.Test Plan
To verify this fix, the following test cases should be considered:
Test Case 1: Simple Instantiated Generic Type Cycle
Test Case 2: Complex Instantiated Generic Type Cycle
Test Case 3: Non-Generic Type Cycle (No Change Expected)
Test Case 4: Cycle Involving Imported Generic Types
Fixes #78006
Summary
This PR addresses issue #78006 by ensuring that cycle error messages for instantiated generic types include their type arguments. Previously, these error messages would only show the generic type's name, making it difficult to pinpoint the exact recursive type causing the error. By including the type arguments, the error messages become more informative and actionable.
Changes
src/cmd/compile/internal/types2/decl.go:objTypeNamethat formatsObjects, specificallyTypeNameobjects that are instances of generic types, to include their type arguments (e.g.,Type[Arg1, Arg2]).pathStringto utilizeobjTypeNamefor formatting objects in the cycle path.namehelper function withincycleErrorto also useobjTypeNamewhen constructing error messages for declaration cycles.