Skip to content

Commit 153d7b9

Browse files
JSMonkSpace Team
authored andcommitted
[K/JS] Change strategy for implicitly exported declarations if there is a cycled reference
^KT-57356 Fixed
1 parent 3be65ec commit 153d7b9

File tree

5 files changed

+61
-2
lines changed

5 files changed

+61
-2
lines changed

compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/export/ExportModelGenerator.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -549,13 +549,17 @@ class ExportModelGenerator(val context: JsIrBackendContext, val generateNamespac
549549
)
550550
}
551551

552+
private val currentlyProcessedTypes = hashSetOf<IrType>()
553+
552554
private fun exportType(type: IrType, shouldCalculateExportedSupertypeForImplicit: Boolean = true): ExportedType {
553-
if (type is IrDynamicType)
555+
if (type is IrDynamicType || type in currentlyProcessedTypes)
554556
return ExportedType.Primitive.Any
555557

556558
if (type !is IrSimpleType)
557559
return ExportedType.ErrorType("NonSimpleType ${type.render()}")
558560

561+
currentlyProcessedTypes.add(type)
562+
559563
val classifier = type.classifier
560564
val isMarkedNullable = type.isMarkedNullable()
561565
val nonNullType = type.makeNotNull() as IrSimpleType
@@ -625,6 +629,7 @@ class ExportModelGenerator(val context: JsIrBackendContext, val generateNamespac
625629
}
626630

627631
return exportedType.withNullability(isMarkedNullable)
632+
.also { currentlyProcessedTypes.remove(type) }
628633
}
629634

630635
private fun IrDeclarationWithName.getExportedIdentifier(): String =

js/js.translator/testData/typescript-export/implicit-export/implicit-export.d.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,5 +45,19 @@ declare namespace JS_TESTS {
4545
class TheNewException extends Error {
4646
constructor();
4747
}
48+
interface Service<Self extends foo.Service<Self, TEvent>, TEvent extends foo.Event<Self>> {
49+
readonly __doNotUseOrImplementIt: {
50+
readonly "foo.Service": unique symbol;
51+
};
52+
}
53+
interface Event<TService extends foo.Service<TService, any /*UnknownType **/>> {
54+
readonly __doNotUseOrImplementIt: {
55+
readonly "foo.Event": unique symbol;
56+
};
57+
}
58+
class SomeServiceRequest implements foo.Service<any/* foo.SomeService */, foo.Event<any/* foo.SomeService */>/* foo.SomeEvent */> {
59+
constructor();
60+
readonly __doNotUseOrImplementIt: foo.Service<any/* foo.SomeService */, foo.Event<any/* foo.SomeService */>/* foo.SomeEvent */>["__doNotUseOrImplementIt"];
61+
}
4862
}
4963
}

js/js.translator/testData/typescript-export/implicit-export/implicit-export.kt

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,4 +95,17 @@ fun functionWithTypeAliasInside(x: NotExportedTypeAlias): NotExportedTypeAlias {
9595
}
9696

9797
@JsExport
98-
class TheNewException: Throwable()
98+
class TheNewException: Throwable()
99+
100+
// Recursive definition KT-57356
101+
@JsExport
102+
interface Service<Self : Service<Self, TEvent>, in TEvent : Event<Self>>
103+
104+
@JsExport
105+
interface Event<out TService : Service<out TService, *>>
106+
107+
class SomeService : Service<SomeService, SomeEvent>
108+
class SomeEvent : Event<SomeService>
109+
110+
@JsExport
111+
class SomeServiceRequest : Service<SomeService, SomeEvent>

js/js.translator/testData/typescript-export/strict-implicit-export/strict-implicit-export.d.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,20 @@ declare namespace JS_TESTS {
7979
}
8080
function acceptForthLike<T extends foo.Forth>(forth: T): void;
8181
function acceptMoreGenericForthLike<T extends foo.IB & foo.IC & foo.Third>(forth: T): void;
82+
interface Service<Self extends foo.Service<Self, TEvent>, TEvent extends foo.Event<Self>> {
83+
readonly __doNotUseOrImplementIt: {
84+
readonly "foo.Service": unique symbol;
85+
};
86+
}
87+
interface Event<TService extends foo.Service<TService, any /*UnknownType **/>> {
88+
readonly __doNotUseOrImplementIt: {
89+
readonly "foo.Event": unique symbol;
90+
};
91+
}
92+
class SomeServiceRequest implements foo.Service<any/* foo.SomeService */, foo.Event<any/* foo.SomeService */>/* foo.SomeEvent */> {
93+
constructor();
94+
readonly __doNotUseOrImplementIt: foo.Service<any/* foo.SomeService */, foo.Event<any/* foo.SomeService */>/* foo.SomeEvent */>["__doNotUseOrImplementIt"];
95+
}
8296
interface NonExportedParent {
8397
readonly __doNotUseOrImplementIt: {
8498
readonly "foo.NonExportedParent": unique symbol;

js/js.translator/testData/typescript-export/strict-implicit-export/strict-implicit-export.kt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,3 +167,16 @@ fun <T> acceptMoreGenericForthLike(forth: T) where T: IB, T: IC, T: Third {}
167167

168168
@JsExport
169169
val forth = Forth()
170+
171+
// Recursive definition KT-57356
172+
@JsExport
173+
interface Service<Self : Service<Self, TEvent>, in TEvent : Event<Self>>
174+
175+
@JsExport
176+
interface Event<out TService : Service<out TService, *>>
177+
178+
class SomeService : Service<SomeService, SomeEvent>
179+
class SomeEvent : Event<SomeService>
180+
181+
@JsExport
182+
class SomeServiceRequest : Service<SomeService, SomeEvent>

0 commit comments

Comments
 (0)