Skip to content

Skip keys that clash with generated C# class members - #1315

Open
jsskeen-utah wants to merge 2 commits into
dmno-dev:mainfrom
jsskeen-utah:fix-csharp-generated-member-names
Open

jsskeen-utah wants to merge 2 commits into
dmno-dev:mainfrom
jsskeen-utah:fix-csharp-generated-member-names

Conversation

@jsskeen-utah

@jsskeen-utah jsskeen-utah commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #1313.

Summary

The C# generator now leaves out keys whose PascalCase names clash with members of the generated class. The clashing names are:

  • Members the generated class declares: Load, SensitiveKeys, DecryptBlob
  • Members every C# object inherits from System.Object: Equals, GetHashCode, GetType, ToString, MemberwiseClone, Finalize
  • The class name itself, since C# rejects a member named after its enclosing type (CS0542). For example, ENV with the default Env, or APP_ENV with class=AppEnv.

These keys go through the same omitted-keys path as reserved words. The generated file's header lists them, and the rest of the class still compiles.

LOAD=x         -> omitted (Load clashes with Env.Load())
GET_TYPE=x     -> omitted (GetType clashes with object.GetType())
ENV=x          -> omitted in class Env (CS0542)
DB_HOST=x      -> property DbHost

Behavior change

Before this PR, a schema with one of these keys produced a class that didn't compile, so none of its keys could be loaded through the generated module. Now the class compiles without the clashing keys. Those keys are still injected as environment variables.

Evidence

  • Before: LOAD fails with CS0102, GET_TYPE with CS0108, and ENV in class Env with CS0542.
  • After: the same schemas compile with Add-Type in each environment below. The class still has Load(), and only the non-clashing keys become properties.
  • Unit tests in packages/varlock/src/env-graph/test/type-generation pass (142), including csharp.test.ts cases for the object and generated members and for the class-name case.
OS .NET runtime Result
Debian 13 (trixie), Linux .NET 10.0.15 Compiles; only the non-clashing properties exposed
Windows 11 Pro 10.0.26300 .NET 11.0.0 Compiles; Load present, only DbHost as a property
Windows 11 Pro 10.0.26300 .NET 8.0.33 Compiles; Load present, only DbHost as a property

The class-name case (ENV in class Env, and APP_ENV in class AppEnv) was compiled on Linux and on both Windows .NET runtimes.

Merge Danger

Door: two-way. The change only affects schemas that contain one of the listed names.

Blast radius: C# users who have a key with one of these names. Their generated class changes from non-compiling to compiling without that key.

Follow-up

The omitted-keys note says "not valid identifiers", which isn't accurate for these keys. Fixing the wording would change the shared note for other emitters, so I've left it for a separate change.

A key such as LOAD becomes a property named Load, which clashes with the generated static Load() method, and GET_TYPE clashes with the inherited object.GetType(). The generated module then fails to compile, so none of its keys load. These keys now go through the same omitted-keys path as reserved words and are listed in the generated file's header.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Important

The collision filter misses the enclosing class name, leaving another case that produces uncompilable C#.

Approach: Reusing the omitted-key path is appropriate, but the name check needs to include the effective class name.

Reviewed changes Reviewed the C# collision exclusions, regression test, and release note.

  • Member exclusions: Properties matching generated helpers or inherited System.Object members are omitted and listed in the header.
  • Regression coverage: The new test checks LOAD and GET_TYPE; all 141 type-generation tests pass, and compiler probes confirm the listed exclusions work.
  • Release note: Documents omitted keys and the compilation fix.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using gpt-6.1-sol | 𝕏

A key such as ENV becomes a property named Env, which is the same name as the default class Env, and APP_ENV does the same for class=AppEnv. C# rejects a member with its enclosing type's name (CS0542). The class name is now resolved before fields are partitioned, so those keys take the omitted-key path too.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ No new issues found.

Reviewed changes Reviewed the enclosing-class collision fix since the previous review.

  • Resolved class names first: Validated the effective class name before filtering and omitted properties matching it.
  • Added regression coverage: Covered ENV with default Env and APP_ENV with custom AppEnv, preserving other properties and omitted-key headers.

All 142 type-generation tests passed. Both generated classes compiled and loaded successfully, retaining omitted sensitive keys in SensitiveKeys.

Pullfrog  | View workflow run | Using gpt-6.1-sol | 𝕏

This branch has not been deployed

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

C# generator emits uncompilable class for keys named LOAD (and other generated member names)

1 participant