Skip to content

Commit

Permalink
[K/JS] Change strategy for implicitly exported declarations if there …
Browse files Browse the repository at this point in the history
…is a cycled reference

^KT-57356 Fixed
  • Loading branch information
JSMonk authored and qodana-bot committed Apr 19, 2023
1 parent 3be65ec commit 153d7b9
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -549,13 +549,17 @@ class ExportModelGenerator(val context: JsIrBackendContext, val generateNamespac
)
}

private val currentlyProcessedTypes = hashSetOf<IrType>()

private fun exportType(type: IrType, shouldCalculateExportedSupertypeForImplicit: Boolean = true): ExportedType {
if (type is IrDynamicType)
if (type is IrDynamicType || type in currentlyProcessedTypes)
return ExportedType.Primitive.Any

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

currentlyProcessedTypes.add(type)

val classifier = type.classifier
val isMarkedNullable = type.isMarkedNullable()
val nonNullType = type.makeNotNull() as IrSimpleType
Expand Down Expand Up @@ -625,6 +629,7 @@ class ExportModelGenerator(val context: JsIrBackendContext, val generateNamespac
}

return exportedType.withNullability(isMarkedNullable)
.also { currentlyProcessedTypes.remove(type) }
}

private fun IrDeclarationWithName.getExportedIdentifier(): String =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,19 @@ declare namespace JS_TESTS {
class TheNewException extends Error {
constructor();
}
interface Service<Self extends foo.Service<Self, TEvent>, TEvent extends foo.Event<Self>> {
readonly __doNotUseOrImplementIt: {
readonly "foo.Service": unique symbol;
};
}
interface Event<TService extends foo.Service<TService, any /*UnknownType **/>> {
readonly __doNotUseOrImplementIt: {
readonly "foo.Event": unique symbol;
};
}
class SomeServiceRequest implements foo.Service<any/* foo.SomeService */, foo.Event<any/* foo.SomeService */>/* foo.SomeEvent */> {
constructor();
readonly __doNotUseOrImplementIt: foo.Service<any/* foo.SomeService */, foo.Event<any/* foo.SomeService */>/* foo.SomeEvent */>["__doNotUseOrImplementIt"];
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,17 @@ fun functionWithTypeAliasInside(x: NotExportedTypeAlias): NotExportedTypeAlias {
}

@JsExport
class TheNewException: Throwable()
class TheNewException: Throwable()

// Recursive definition KT-57356
@JsExport
interface Service<Self : Service<Self, TEvent>, in TEvent : Event<Self>>

@JsExport
interface Event<out TService : Service<out TService, *>>

class SomeService : Service<SomeService, SomeEvent>
class SomeEvent : Event<SomeService>

@JsExport
class SomeServiceRequest : Service<SomeService, SomeEvent>
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,20 @@ declare namespace JS_TESTS {
}
function acceptForthLike<T extends foo.Forth>(forth: T): void;
function acceptMoreGenericForthLike<T extends foo.IB & foo.IC & foo.Third>(forth: T): void;
interface Service<Self extends foo.Service<Self, TEvent>, TEvent extends foo.Event<Self>> {
readonly __doNotUseOrImplementIt: {
readonly "foo.Service": unique symbol;
};
}
interface Event<TService extends foo.Service<TService, any /*UnknownType **/>> {
readonly __doNotUseOrImplementIt: {
readonly "foo.Event": unique symbol;
};
}
class SomeServiceRequest implements foo.Service<any/* foo.SomeService */, foo.Event<any/* foo.SomeService */>/* foo.SomeEvent */> {
constructor();
readonly __doNotUseOrImplementIt: foo.Service<any/* foo.SomeService */, foo.Event<any/* foo.SomeService */>/* foo.SomeEvent */>["__doNotUseOrImplementIt"];
}
interface NonExportedParent {
readonly __doNotUseOrImplementIt: {
readonly "foo.NonExportedParent": unique symbol;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,3 +167,16 @@ fun <T> acceptMoreGenericForthLike(forth: T) where T: IB, T: IC, T: Third {}

@JsExport
val forth = Forth()

// Recursive definition KT-57356
@JsExport
interface Service<Self : Service<Self, TEvent>, in TEvent : Event<Self>>

@JsExport
interface Event<out TService : Service<out TService, *>>

class SomeService : Service<SomeService, SomeEvent>
class SomeEvent : Event<SomeService>

@JsExport
class SomeServiceRequest : Service<SomeService, SomeEvent>

0 comments on commit 153d7b9

Please sign in to comment.