Skip to content

Commit

Permalink
Fix stop running decorators on partially instantiated operations (#3227)
Browse files Browse the repository at this point in the history
fix [#2619](#2619)
  • Loading branch information
timotheeguerin authored Apr 26, 2024
1 parent 0a83800 commit 32a25ec
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -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)
2 changes: 1 addition & 1 deletion packages/compiler/src/core/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 3 additions & 1 deletion packages/compiler/src/core/projector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
21 changes: 20 additions & 1 deletion packages/compiler/test/checker/interface.test.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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> {
Expand Down

0 comments on commit 32a25ec

Please sign in to comment.