diff --git a/gradle.properties b/gradle.properties index 8b357a39..df33a4fa 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,7 +1,7 @@ systemProp.kotlinVersion=2.0.0-RC1 systemProp.kotlinIdeVersion=1.9.20-506 systemProp.kotlinIdeVersionSuffix=IJ8109.175 -systemProp.swiftExportVersion=2.0.20-dev-1552 +systemProp.swiftExportVersion=2.0.20-dev-2553 systemProp.policy=executor.policy systemProp.indexes=indexes.json systemProp.indexesJs=indexesJs.json diff --git a/src/test/kotlin/com/compiler/server/SwiftConverterTest.kt b/src/test/kotlin/com/compiler/server/SwiftConverterTest.kt index eb546db8..d5019d96 100644 --- a/src/test/kotlin/com/compiler/server/SwiftConverterTest.kt +++ b/src/test/kotlin/com/compiler/server/SwiftConverterTest.kt @@ -45,11 +45,10 @@ class SwiftConverterTest : BaseExecutorTest() { fun `class declaration`() = exactTest( input = "public class MyClass { public fun A() {}}", expected = """ - import KotlinBridges import KotlinRuntime - - public class MyClass { - public init() { + + public class MyClass : KotlinRuntime.KotlinBase { + public override init() { fatalError() } public func A() -> Swift.Void { @@ -67,9 +66,6 @@ class SwiftConverterTest : BaseExecutorTest() { val myProperty: Int = 42 """.trimIndent(), expected = """ - import KotlinBridges - import KotlinRuntime - public extension Playground.foo.bar { public static var myProperty: Swift.Int32 { get { @@ -87,15 +83,17 @@ class SwiftConverterTest : BaseExecutorTest() { @Test fun `invalid code`() = exactTest( input = "abracadabra", - // For now, we unconditionally import a few modules. Will be gone in the future versions expected = """ - import KotlinBridges - import KotlinRuntime """.trimIndent() ) @Test - fun `more invalid code`() = shouldFailTest( + fun `more invalid code`() = exactTest( input = "fun foo(): Bar = error()", + expected = """ + public func foo() -> ERROR_TYPE { + fatalError() + } + """.trimIndent() ) } \ No newline at end of file diff --git a/swift-export-playground/src/main/kotlin/PlaygroundSirSession.kt b/swift-export-playground/src/main/kotlin/PlaygroundSirSession.kt index 616988e3..cc603c34 100644 --- a/swift-export-playground/src/main/kotlin/PlaygroundSirSession.kt +++ b/swift-export-playground/src/main/kotlin/PlaygroundSirSession.kt @@ -1,34 +1,31 @@ -import org.jetbrains.kotlin.analysis.api.KtAnalysisSession +import org.jetbrains.kotlin.analysis.project.structure.KtModule import org.jetbrains.kotlin.sir.providers.SirSession +import org.jetbrains.kotlin.sir.providers.SirTypeProvider import org.jetbrains.kotlin.sir.providers.impl.* import org.jetbrains.sir.lightclasses.SirDeclarationFromKtSymbolProvider internal class PlaygroundSirSession( - private val ktAnalysisSession: KtAnalysisSession, + ktModule: KtModule, ) : SirSession { override val declarationNamer = SirDeclarationNamerImpl() override val enumGenerator = SirEnumGeneratorImpl() - override val moduleProvider = SirSingleModuleProvider("Playground", "KotlinBridges") + override val moduleProvider = SirSingleModuleProvider("Playground") override val declarationProvider = CachingSirDeclarationProvider( declarationsProvider = SirDeclarationFromKtSymbolProvider( - ktAnalysisSession = ktAnalysisSession, + ktModule = ktModule, sirSession = sirSession, ) ) override val parentProvider = SirParentProviderImpl( - ktAnalysisSession = ktAnalysisSession, sirSession = sirSession, ) override val typeProvider = SirTypeProviderImpl( - ktAnalysisSession = ktAnalysisSession, - sirSession = sirSession, - ) - override val visibilityChecker = SirVisibilityCheckerImpl( - ktAnalysisSession = ktAnalysisSession, + errorTypeStrategy = SirTypeProvider.ErrorTypeStrategy.ErrorType, + unsupportedTypeStrategy = SirTypeProvider.ErrorTypeStrategy.ErrorType, sirSession = sirSession, ) + override val visibilityChecker = SirVisibilityCheckerImpl() override val childrenProvider = SirDeclarationChildrenProviderImpl( - ktAnalysisSession = ktAnalysisSession, sirSession = sirSession, ) } \ No newline at end of file diff --git a/swift-export-playground/src/main/kotlin/Runner.kt b/swift-export-playground/src/main/kotlin/Runner.kt index cc11ea57..c74b0f0a 100644 --- a/swift-export-playground/src/main/kotlin/Runner.kt +++ b/swift-export-playground/src/main/kotlin/Runner.kt @@ -24,12 +24,12 @@ fun runSwiftExport( ): String { val (ktModule, sources) = collectModuleAndSources(sourceFile, "Playground", stdlibPath) - val sirModule: SirModule = analyze(ktModule) { - val sirSession = PlaygroundSirSession(analysisSession) - with(sirSession) { + return analyze(ktModule) { + val sirSession = PlaygroundSirSession(ktModule) + val sirModule: SirModule = with(sirSession) { ktModule.sirModule().also { sources.flatMap { file -> - file.getFileSymbol().getFileScope().extractDeclarations() + file.getFileSymbol().getFileScope().extractDeclarations(analysisSession) }.forEach { topLevelDeclaration -> val parent = topLevelDeclaration.parent as? SirMutableDeclarationContainer ?: error("top level declaration can contain only module or extension to package as a parent") @@ -37,8 +37,8 @@ fun runSwiftExport( } } } + SirAsSwiftSourcesPrinter.print(sirModule, stableDeclarationsOrder = true, renderDocComments = true) } - return SirAsSwiftSourcesPrinter.print(sirModule, stableDeclarationsOrder = true, renderDocComments = true) } @OptIn(KtAnalysisApiInternals::class) diff --git a/swift-export-playground/src/test/kotlin/Tests.kt b/swift-export-playground/src/test/kotlin/Tests.kt index 290fd642..6923db7e 100644 --- a/swift-export-playground/src/test/kotlin/Tests.kt +++ b/swift-export-playground/src/test/kotlin/Tests.kt @@ -26,12 +26,25 @@ class SwiftExportTests { fun foo(): Int = 5 """, """ - import KotlinBridges - import KotlinRuntime - public func foo() -> Swift.Int32 { fatalError() } """ ) + + @Test + fun `class declaration`() = testSources( + """ + class A + """.trimIndent(), + """ + import KotlinRuntime + + public class A : KotlinRuntime.KotlinBase { + public override init() { + fatalError() + } + } + """.trimIndent() + ) } \ No newline at end of file