Skip to content

str/list/dict/bool parameters generate C++ without <string>/<vector>/<map>, C# without System.Collections.Generic, and C without <stdbool.h>, so none compile #334

Open

Description

@matt-edmondson

What's wrong

The generators translate the AST's portable type names into library types:

  • C++ (CppGenerator.cs L45-L64): str → std::string, list → std::vector, dict → std::map, object → std::any.
  • C# (CSharpGenerator.cs L1502-L1525): list → List, dict → Dictionary.
  • C (CGenerator.cs L94-L112): bool stays bool, which C99 provides only through <stdbool.h>.

There is already a mechanism for adding the imports generated output needs: RequiredImports (LanguageGeneratorBase.cs L624, used at L710). The generators don't use it for these types:

  • C++ adds <vector>/<string> only when an entry point takes arguments (CppGenerator.cs L154-L172). It never adds them for a mapped parameter, field or return type.
  • C adds only <math.h> (CGenerator.cs L183-L190).
  • C# does not override RequiredImports at all.

Rust avoids the problem by spelling std::collections::HashMap and std::any::Any in full. Go and Python map these names to builtins.

Reproduction (HEAD 667637c)

Input: a SourceFile containing int count(str label, list<int> sizes, dict<str, int> names, bool ready) { return 0; }

Target Output Result
C++ int count(std::string label, std::vector<int> sizes, std::map<std::string, int> names, bool ready) g++ -std=c++20: 'string'/'vector'/'map' is not a member of 'std'
C# public static int count(string label, List<int> sizes, Dictionary<string, int> names, bool ready) dotnet build: CS0246 for List<> and Dictionary<,>
C int count(const char* label, int* sizes, void* names, bool ready) gcc -std=c99: unknown type name 'bool'
Rust, Go, Python valid

The existing C compile tests pass only because they add <stdbool.h> by hand (CGeneratedSourceCompilesTests.cs L267).

Suggested fix / acceptance criteria

  • C++ RequiredImports yields <string>, <vector>, <map> and <any> whenever a type spelled in the file maps to one of them.
  • C RequiredImports yields <stdbool.h> when bool is used.
  • C# either:
    • fully qualifies the types (global::System.Collections.Generic.List<…>, as Rust does), which also works when the generation root is not a SourceFile; or
    • adds a RequiredImports override.
  • Compile tests in C++, C# and C cover a function using these types, with no imports supplied by the caller.

There is precedent for the generator adding the imports its own spellings need: #147 and #278.

Activity

  1. added
    bug
    on Oct 20, 2026
  2. matt-edmondson commented on Oct 20, 2026

    @matt-edmondson
    ContributorAuthor

    Triage


    Generated by Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions