Repository navigation
Description
What's wrong
CLAUDE.md says that when Go writes a generic type down, a mention of the type carries no arguments, because a type declared without parameters takes none. GoGenerator.SpellTypeName drops the arguments only when the mentioned name equals writtenDownType, which is the type currently being written:
Coder/Coder/Languages/GoGenerator.cs
Lines 2369 to 2395 in 89d8424
| private string SpellTypeName(TypeReference type) | |
| { | |
| string unknown = TypeMappings[UnknownTypeName]; | |
| if (string.Equals(type.Name, "list", StringComparison.OrdinalIgnoreCase)) | |
| { | |
| return $"[]{(type.TypeArguments.Count == 1 ? SpellType(type.TypeArguments[0]) : unknown)}"; | |
| } | |
| if (string.Equals(type.Name, "dict", StringComparison.OrdinalIgnoreCase)) | |
| { | |
| return type.TypeArguments.Count == 2 | |
| ? $"map[{SpellType(type.TypeArguments[0])}]{SpellType(type.TypeArguments[1])}" | |
| : $"map[{StringTypeName}]{unknown}"; | |
| } | |
| if (writtenDownParameters.Contains(type.Name)) | |
| { | |
| return unknown; | |
| } | |
| string name = TypeMappings.TryGetValue(type.Name, out string? mapped) ? mapped : type.Name; | |
| return type.TypeArguments.Count == 0 || string.Equals(name, writtenDownType, StringComparison.Ordinal) | |
| ? name | |
| : $"{name}[{string.Join(", ", type.TypeArguments.Select(SpellType))}]"; | |
| } |
Every mention of that type from outside its own declaration keeps […]:
- a field of another struct;
- a parameter or return type of a free function;
- the interface assertion
var _ X[int] = (*T)(nil).
Python has the same gap in one place. class Source: is written with its type parameters as a comment, but PythonBaseFromGenericType still writes the base as Source[int]. A base list is evaluated when the class statement runs, so the module fails on import. Annotations are unaffected because from __future__ import annotations defers them.
Repro 1
Input: struct Box with TypeParameter("T") and field value: T; struct Shelf with field item: Box<int>; free function width(b: Box<int>) -> int.
type Box struct { value any }
type Shelf struct { item Box[int] } // go build: invalid operation: Box[int] (Box is not a generic type)
func width(b Box[int]) int { return 1 } // same errorRepro 2
Input: interface Source<T> with abstract next() -> T; class Counter with Interfaces = [Source<int>].
- Go:
var _ Source[int] = (*Counter)(nil)gives "Source is not a generic type". - Python:
class Source:…class Counter(Source[int]):raisesTypeError: type 'Source' is not subscriptableon import.
C#, C++ and Rust compile both repros. Both were confirmed by generating the output and running go build and python3 on it.
Suggested fix / acceptance criteria
- Go: collect the names of every type in the generation root that is written down (has
TypeParameters). Drop the type arguments from any mention of those names anywhere in the file, the interface assertion included, so the documented rule holds file-wide. - Python: when a base names a class in the same document that was written down, write the base without arguments.
- Add both repros to
GoGeneratedSourceCompilesTestsandPythonGeneratedSourceImportsTests. The existing Python test injects its generic interfaces from outside the file, so it never covers a generic declared in the same document.
Related: #63, closed, fixed only the mention inside the type's own declaration.
Activity
matt-edmondson commentedon Oct 30, 2026
Triage
go buildand Python output fails on import when a generic type declared in the same document is mentioned with type arguments outside its own declaration.Coder/Languages/GoGenerator.csSpellTypeName(writtenDownType) and the interface-assertion emission;PythonBaseFromGenericTypein the Python generator. Tests go inGoGeneratedSourceCompilesTestsandPythonGeneratedSourceImportsTests.Tis never used") #387 is adjacent Rust generic work.Generated by Claude Code