From 1f82d65ea04134d7182158cf3cc98158b6923f87 Mon Sep 17 00:00:00 2001 From: Timothee Guerin Date: Tue, 11 Jun 2024 15:10:35 -0700 Subject: [PATCH] Do not run decorators on cloned type if the original type wasn't finished (#3566) In the same way we have this logic for `cloneTypeForSymbol` --- ...one-type-donot-finish-unfinished-2024-5-11-21-54-41.md | 8 ++++++++ packages/compiler/src/core/checker.ts | 5 ++++- 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 .chronus/changes/fix-clone-type-donot-finish-unfinished-2024-5-11-21-54-41.md diff --git a/.chronus/changes/fix-clone-type-donot-finish-unfinished-2024-5-11-21-54-41.md b/.chronus/changes/fix-clone-type-donot-finish-unfinished-2024-5-11-21-54-41.md new file mode 100644 index 0000000000..947d8feafe --- /dev/null +++ b/.chronus/changes/fix-clone-type-donot-finish-unfinished-2024-5-11-21-54-41.md @@ -0,0 +1,8 @@ +--- +# Change versionKind to one of: internal, fix, dependencies, feature, deprecation, breaking +changeKind: fix +packages: + - "@typespec/compiler" +--- + +[API] Do not run decorators on cloned type if the original type wasn't finished diff --git a/packages/compiler/src/core/checker.ts b/packages/compiler/src/core/checker.ts index 1647ece4e6..17d055307c 100644 --- a/packages/compiler/src/core/checker.ts +++ b/packages/compiler/src/core/checker.ts @@ -6512,7 +6512,10 @@ export function createChecker(program: Program): Checker { * recursively by the caller. */ function cloneType(type: T, additionalProps: Partial = {}): T { - const clone = finishType(initializeClone(type, additionalProps)); + let clone = initializeClone(type, additionalProps); + if (type.isFinished) { + clone = finishType(clone); + } const projection = projectionsByType.get(type); if (projection) { projectionsByType.set(clone, projection);