Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes versioning when using versioned named union variants #4408

Merged
merged 3 commits into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
changeKind: fix
packages:
- "@typespec/versioning"
---

Fixes versioning when using versioned named union variants
6 changes: 4 additions & 2 deletions packages/versioning/src/validate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -533,8 +533,10 @@ function validateReference(program: Program, source: Type | Type[], target: Type

switch (target.kind) {
case "Union":
for (const variant of target.variants.values()) {
validateReference(program, source, variant.type);
if (typeof target.name !== "string") {
for (const variant of target.variants.values()) {
validateReference(program, source, variant.type);
}
}
break;
case "Tuple":
Expand Down
25 changes: 25 additions & 0 deletions packages/versioning/test/versioning.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -680,6 +680,31 @@ describe("versioning: logic", () => {
strictEqual((v6 as any as IntrinsicType).name, "never");
});

it("does not emit diagnostic when using named versioned union variant in incompatible versioned source", async () => {
const diagnostics = await runner.diagnose(`
@versioned(Versions)
namespace TestService {
enum Versions {v1, v2}
@added(Versions.v2)
model Versioned {}
union NamedUnion {
string;
@added(Versions.v2)
Versioned;
}
@added(Versions.v1)
model Foo {
content: NamedUnion;
}
}
`);
expectDiagnosticEmpty(diagnostics);
});

async function versionedUnion(versions: string[], union: string) {
const { Test } = (await runner.compile(`
@versioned(Versions)
Expand Down
Loading