Skip to content

Commit

Permalink
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 2 deletions.
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

0 comments on commit d7a0884

Please sign in to comment.