diff --git a/common/changes/@typespec/compiler/fix-caching-invalid_2023-10-30-22-27.json b/common/changes/@typespec/compiler/fix-caching-invalid_2023-10-30-22-27.json new file mode 100644 index 0000000000..5945164bd2 --- /dev/null +++ b/common/changes/@typespec/compiler/fix-caching-invalid_2023-10-30-22-27.json @@ -0,0 +1,10 @@ +{ + "changes": [ + { + "packageName": "@typespec/compiler", + "comment": "", + "type": "none" + } + ], + "packageName": "@typespec/compiler" +} \ No newline at end of file diff --git a/packages/compiler/src/core/checker.ts b/packages/compiler/src/core/checker.ts index 2feba122bb..5bfaf2b144 100644 --- a/packages/compiler/src/core/checker.ts +++ b/packages/compiler/src/core/checker.ts @@ -2152,16 +2152,17 @@ export function createChecker(program: Program): Checker { mapper: TypeMapper | undefined, options?: Partial | boolean ): Sym | undefined { - if (mapper === undefined && referenceSymCache.has(node)) { - return referenceSymCache.get(node); - } - const resolvedOptions: SymbolResolutionOptions = typeof options === "boolean" ? { ...defaultSymbolResolutionOptions, resolveDecorators: options } : { ...defaultSymbolResolutionOptions, ...(options ?? {}) }; + if (mapper === undefined && resolvedOptions.checkTemplateTypes && referenceSymCache.has(node)) { + return referenceSymCache.get(node); + } const sym = resolveTypeReferenceSymInternal(node, mapper, resolvedOptions); - referenceSymCache.set(node, sym); + if (resolvedOptions.checkTemplateTypes) { + referenceSymCache.set(node, sym); + } return sym; } diff --git a/packages/compiler/test/checker/interface.test.ts b/packages/compiler/test/checker/interface.test.ts index cce6337dec..cf9d5e63a4 100644 --- a/packages/compiler/test/checker/interface.test.ts +++ b/packages/compiler/test/checker/interface.test.ts @@ -438,6 +438,28 @@ describe("compiler: interfaces", () => { message: `Can't pass template arguments to non-templated type`, }); }); + + // https://github.com/microsoft/typespec/pull/2617 + it("can 'op is' a templated operation inside templated interface", async () => { + const { myBar } = (await runner.compile(` + interface Foo { + bar(input: A): B; + } + + alias MyFoo = Foo; + @test op myBar is MyFoo.bar; + `)) as { + myBar: Operation; + }; + + const input = myBar.parameters.properties.get("input")!.type; + strictEqual(input.kind, "Scalar" as const); + strictEqual(input.name, "string"); + + const returnType = myBar.returnType; + strictEqual(returnType.kind, "Scalar" as const); + strictEqual(returnType.name, "int32"); + }); }); it("can decorate extended operations independently", async () => {