Fix stop running decorators on partially instantiated operations (#3227)

fix [#2619](https://github.com/microsoft/typespec/issues/2619)
This commit is contained in:
Timothee Guerin 2024-04-26 14:46:15 -07:00 коммит произвёл GitHub
Родитель 0a83800065
Коммит 32a25ecb94
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
4 изменённых файлов: 32 добавлений и 3 удалений

Просмотреть файл

@ -0,0 +1,8 @@
---
# Change versionKind to one of: internal, fix, dependencies, feature, deprecation, breaking
changeKind: fix
packages:
- "@typespec/compiler"
---
Stop running decorators on partially instantiated operations(When interface is instantiated but not the operation)

Просмотреть файл

@ -2865,7 +2865,7 @@ export function createChecker(program: Program): Checker {
}
// Some of the mapper args are still template parameter so we shouldn't create the type.
return mapper.args.every((t) => t.kind !== "TemplateParameter");
return !mapper.partial && mapper.args.every((t) => t.kind !== "TemplateParameter");
}
function checkModelExpression(node: ModelExpressionNode, mapper: TypeMapper | undefined) {

Просмотреть файл

@ -416,7 +416,9 @@ export function createProjector(
projectedOp.namespace = projectedNamespaceScope();
}
finishTypeForProgram(projectedProgram, projectedOp);
if (op.isFinished) {
finishTypeForProgram(projectedProgram, projectedOp);
}
if (op.interface) {
projectedOp.interface = projectType(op.interface) as Interface;
}

Просмотреть файл

@ -1,5 +1,5 @@
import { deepStrictEqual, notStrictEqual, ok, strictEqual } from "assert";
import { beforeEach, describe, it } from "vitest";
import { beforeEach, describe, expect, it, vi } from "vitest";
import { isTemplateDeclaration } from "../../src/core/type-utils.js";
import { Interface, Model, Operation, Type } from "../../src/core/types.js";
import { getDoc } from "../../src/index.js";
@ -410,6 +410,25 @@ describe("compiler: interfaces", () => {
strictEqual(returnType.name, "int32");
});
it("instantiating an templated interface doesn't finish template operation inside", async () => {
const $track = vi.fn();
testHost.addJsFile("dec.js", { $track });
testHost.addTypeSpecFile(
"main.tsp",
`
import "./dec.js";
interface Base<A> {
@track bar<B>(input: A): B;
}
alias My = Base<string>;
`
);
await testHost.compile("./");
expect($track).not.toHaveBeenCalled();
});
it("emit warning if shadowing parent templated type", async () => {
const diagnostics = await runner.diagnose(`
interface Base<A> {