diff --git a/.chronus/changes/fix-versioning-validation-regression-2026-0-23-18-52-52.md b/.chronus/changes/fix-versioning-validation-regression-2026-0-23-18-52-52.md new file mode 100644 index 00000000000..ed758a2a0a4 --- /dev/null +++ b/.chronus/changes/fix-versioning-validation-regression-2026-0-23-18-52-52.md @@ -0,0 +1,8 @@ +--- +# Change versionKind to one of: internal, fix, dependencies, feature, deprecation, breaking +changeKind: internal +packages: + - "@typespec/versioning" +--- + +Fix versioning validation regression diff --git a/packages/versioning/src/validate.ts b/packages/versioning/src/validate.ts index bd76aba3b0c..c61de96087a 100644 --- a/packages/versioning/src/validate.ts +++ b/packages/versioning/src/validate.ts @@ -535,12 +535,13 @@ function validateReference(program: Program, source: Type | Type[], target: Type } } + const sources = Array.isArray(source) ? source : [source]; switch (target.kind) { case "Model": // For anonymous model expressions (inline models), validate their properties if (!target.name) { for (const prop of target.properties.values()) { - validateReference(program, source, prop.type); + validateReference(program, [prop, ...sources], prop.type); } } break; diff --git a/packages/versioning/test/incompatible-versioning.test.ts b/packages/versioning/test/incompatible-versioning.test.ts index 566ee80cea9..9ad0bcc008f 100644 --- a/packages/versioning/test/incompatible-versioning.test.ts +++ b/packages/versioning/test/incompatible-versioning.test.ts @@ -68,8 +68,7 @@ describe("versioning: validate incompatible references", () => { }); describe("operation", () => { - // TODO See: https://github.com/microsoft/typespec/issues/2695 - it.skip("emit diagnostic when unversioned op has a versioned model as a parameter", async () => { + it("emit diagnostic when unversioned op has a versioned model as a parameter", async () => { const diagnostics = await runner.diagnose(` @added(Versions.v2) model Foo {} @@ -111,8 +110,7 @@ describe("versioning: validate incompatible references", () => { }); }); - // TODO See: https://github.com/microsoft/typespec/issues/2695 - it.skip("emit diagnostic when unversioned op based on a template has a versioned model as a parameter", async () => { + it("emit diagnostic when unversioned op based on a template has a versioned model as a parameter", async () => { const diagnostics = await runner.diagnose(` @added(Versions.v2) model Foo {} @@ -1095,6 +1093,17 @@ describe("versioning: validate incompatible references", () => { }); }); + describe("succeed when annotations are correctly defined", () => { + it("on property inside model expression", async () => { + const diagnostics = await runner.diagnose(` + @added(Versions.v3) + model A {} + model B { prop: { @added(Versions.v3) a: A }} + `); + expectDiagnosticEmpty(diagnostics); + }); + }); + describe("report issues inside model expression under model", () => { it("when base model is added before", async () => { const diagnostics = await runner.diagnose(