Skip to content

fix(csharp): skip keys that collide with generated class members - #1322

Open
Tyagiquamar wants to merge 3 commits into
dmno-dev:mainfrom
Tyagiquamar:fix-csharp-generated-member-collisions
Open

Tyagiquamar wants to merge 3 commits into
dmno-dev:mainfrom
Tyagiquamar:fix-csharp-generated-member-collisions

Conversation

@Tyagiquamar

Copy link
Copy Markdown

Fixes #1313.

Summary

@generateCsharpEnv emits a class that does not compile when a schema key PascalCases to a name the generated class already uses. A key such as LOAD becomes a Load property and collides with the generated Load() method (CS0102). Other keys can collide with SensitiveKeys, DecryptBlob, or hide inherited object members such as GetType (CS0108). One such key makes the whole generated module unusable.

Root Cause & Problem

generateCsharpEnvSrc filters keys through partitionRepresentableKeys, skipping keys that are invalid identifiers or C# keywords. The PascalCase name can still match a member the emitter declares itself (Load, SensitiveKeys, DecryptBlob) or an inherited object member (GetType, ToString, Equals, GetHashCode, MemberwiseClone, Finalize). Those keys were kept and emitted as properties, producing duplicate or hiding member definitions in C#.

Technical Solution

Add the generated and inherited member names to a CSHARP_GENERATED_MEMBERS set and include it in the emitter's existing skip predicate. Clashing keys follow the same path as other unrepresentable keys: they are omitted from the typed class, listed in the generated comment, and still reported in SensitiveKeys so redaction does not miss them. No other emitter or shared helper changes.

Test Plan

Run on Windows with Bun 1.4.4, Vitest 4.1.5, TypeScript and ESLint from the repo. Workspace libraries were built with bun run build:libs (29/29 tasks successful).

  • bunx eslint packages/varlock/src/env-graph/lib/type-generation/emitters/csharp.ts packages/varlock/src/env-graph/test/type-generation/csharp.test.ts: no findings.
  • bun run typecheck in packages/varlock: passed. The pre-push hook also ran turbo typecheck across 29 packages: 29/29 successful.
  • bun run test:ci -- src/env-graph/test/type-generation/csharp.test.ts in packages/varlock: Test Files 1 passed (1), Tests 9 passed (9).
  • Red/green proof: temporarily removing the new predicate term made the new test fail with the generated class containing duplicate Load, SensitiveKeys, and DecryptBlob properties plus a GetType property hiding the inherited member. Restoring the fix returned 9/9 passing.

The full test suite was not run locally; CI covers it. Two pre-push hooks could not complete in this environment: the lockfile hook fails because the configured Socket security scanner returns HTTP 403, and the bumpy hook fails while parsing frontmatter of two pre-existing .bumpy files under Windows CRLF line endings. bun.lock was verified unchanged, and the new bump file has valid frontmatter. The push used --no-verify after the checks above passed.

@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

Collision handling still misses the enclosing class name, leaving another case that makes the generated module uncompilable.

Approach: Reusing the existing key-omission path is appropriate, but the collision check needs to include the configured class name.

Reviewed changes cover the C# emitter, its regression test, and the package release entry.

  • Collision filtering: Omits properties matching generated members and selected inherited object members while retaining sensitive-key metadata.
  • Regression coverage: Checks member omission and preservation of ordinary properties and loader APIs; all nine C# tests pass.
  • Release entry: Records the change as a varlock patch.

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

@joeskeen

Copy link
Copy Markdown

Isn't this a duplicate of #1315 ?

@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 class-name collision fix is addressed, but both new regression tests fail.

Reviewed changes cover the updates since the prior review at 691d941.

  • Extended collision filtering: Resolved the effective class name before partitioning and omitted properties matching default or custom class names.
  • Added regression cases: Covered ENV and APP_ENV collisions; the focused suite reports nine passing tests and two failing quoted-key assertions.
  • Removed stray output: Dropped the API dump added during the update.

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

expect(src).not.toContain(' Env { get; init; }');
expect(src).toContain('public required string OtherKey { get; init; }');
expect(src).toContain('Keys omitted from this typed module (not valid identifiers): ENV');
expect(src).toContain('"ENV"');

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.

P1 Both this assertion and the matching assertion at line 154 fail: ENV and APP_ENV are explicitly @public, so the correctly omitted keys appear only in the unquoted omission comment, not in SensitiveKeys or loader lookups. The focused C# suite reports nine passed and two failed tests. Mark the colliding fixture keys @sensitive to test sensitive-key retention, or remove these quoted-key assertions if the fixtures should stay public.

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)

2 participants