From 413f0fa8316013ac492eb7c2dc2be9592b0bf6ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Burzy=C5=84ski?= Date: Wed, 25 Sep 2024 20:04:01 +0200 Subject: [PATCH] Fixed crash when looking for contextual inherited JSDocs for setters and getters (#60027) Co-authored-by: Gabriela Araujo Britto --- src/services/services.ts | 8 ++++++++ .../quickInfoJsDocGetterSetterNoCrash1.ts | 18 ++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 tests/cases/fourslash/quickInfoJsDocGetterSetterNoCrash1.ts diff --git a/src/services/services.ts b/src/services/services.ts index c51089dfe25..641ea043430 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -735,6 +735,8 @@ class SymbolObject implements Symbol { if (context) { if (isGetAccessor(context)) { if (!this.contextualGetAccessorDocumentationComment) { + this.contextualGetAccessorDocumentationComment = emptyArray; // Set temporarily to avoid an infinite loop finding inherited tags + this.contextualGetAccessorDocumentationComment = getDocumentationComment(filter(this.declarations, isGetAccessor), checker); } if (length(this.contextualGetAccessorDocumentationComment)) { @@ -743,6 +745,8 @@ class SymbolObject implements Symbol { } if (isSetAccessor(context)) { if (!this.contextualSetAccessorDocumentationComment) { + this.contextualSetAccessorDocumentationComment = emptyArray; // Set temporarily to avoid an infinite loop finding inherited tags + this.contextualSetAccessorDocumentationComment = getDocumentationComment(filter(this.declarations, isSetAccessor), checker); } if (length(this.contextualSetAccessorDocumentationComment)) { @@ -766,6 +770,8 @@ class SymbolObject implements Symbol { if (context) { if (isGetAccessor(context)) { if (!this.contextualGetAccessorTags) { + this.contextualGetAccessorTags = emptyArray; // Set temporarily to avoid an infinite loop finding inherited tags + this.contextualGetAccessorTags = getJsDocTagsOfDeclarations(filter(this.declarations, isGetAccessor), checker); } if (length(this.contextualGetAccessorTags)) { @@ -774,6 +780,8 @@ class SymbolObject implements Symbol { } if (isSetAccessor(context)) { if (!this.contextualSetAccessorTags) { + this.contextualSetAccessorTags = emptyArray; // Set temporarily to avoid an infinite loop finding inherited tags + this.contextualSetAccessorTags = getJsDocTagsOfDeclarations(filter(this.declarations, isSetAccessor), checker); } if (length(this.contextualSetAccessorTags)) { diff --git a/tests/cases/fourslash/quickInfoJsDocGetterSetterNoCrash1.ts b/tests/cases/fourslash/quickInfoJsDocGetterSetterNoCrash1.ts new file mode 100644 index 00000000000..92e88ebd54c --- /dev/null +++ b/tests/cases/fourslash/quickInfoJsDocGetterSetterNoCrash1.ts @@ -0,0 +1,18 @@ +/// + +// https://github.com/microsoft/TypeScript/issues/60024 + +//// class A implements A { +//// get x(): string { return "" } +//// } +//// const e = new A() +//// e.x/*1*/ +//// +//// class B implements B { +//// set x(v: string) {} +//// } +//// const f = new B() +//// f.x/*2*/ + +verify.quickInfoAt("1", "(property) A.x: string"); +verify.quickInfoAt("2", "(property) B.x: string");