Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"
---

Fix: augmenting template model property could result in sending invalid argument to decorator
3 changes: 1 addition & 2 deletions packages/compiler/src/core/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1981,7 +1981,6 @@ export function createChecker(program: Program): Checker {

function getSymbolLinks(s: Sym): SymbolLinks {
const id = getSymbolId(s);

if (symbolLinks.has(id)) {
return symbolLinks.get(id)!;
}
Expand Down Expand Up @@ -3675,7 +3674,7 @@ export function createChecker(program: Program): Checker {
x.kind === SyntaxKind.DecoratorDeclarationStatement
);
if (decoratorDeclNode) {
checkDecoratorDeclaration(decoratorDeclNode, mapper);
checkDecoratorDeclaration(decoratorDeclNode, undefined);
}
}
if (symbolLinks.declaredType) {
Expand Down
15 changes: 15 additions & 0 deletions packages/compiler/test/checker/decorators.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,21 @@ describe("compiler: checker: decorators", () => {
expectDecoratorNotCalled();
});

// Regresssion test for https://github.com/microsoft/typespec/issues/3211
it("augmenting a template model property before a decorator declaration resolve the declaration correctly", async () => {
await runner.compile(`
model Foo<T> {
prop: T;
}
model Test {foo: Foo<string>}

@@testDec(Foo.prop, "abc");
extern dec testDec(target: unknown, arg1: valueof string);

`);
strictEqual(calledArgs![2], "abc");
});

describe("value marshalling", () => {
async function testCallDecorator(type: string, value: string): Promise<any> {
await runner.compile(`
Expand Down