[JS IR BE] Add Unit return type to function signature

This commit is contained in:
Svyatoslav Kuzmich
2019-05-15 10:35:58 +03:00
parent e8933738ac
commit 23a214710b
9 changed files with 15 additions and 7 deletions
@@ -215,9 +215,9 @@ class FunctionAndSignature(val function: IrSimpleFunction) {
function.name.asString(),
function.extensionReceiverParameter?.type?.asString(),
function.valueParameters.map { it.type.asString() },
// Return type used in signature for inline classes only because
// Return type used in signature for inline classes and Unit because
// they are binary incompatible with supertypes and require bridges.
function.returnType.run { if (isInlined()) asString() else null }
function.returnType.run { if (isInlined() || isUnit()) asString() else null }
)
}
@@ -5,11 +5,13 @@
package org.jetbrains.kotlin.ir.backend.js.utils
import org.jetbrains.kotlin.backend.common.ir.isMethodOfAny
import org.jetbrains.kotlin.backend.common.ir.isTopLevel
import org.jetbrains.kotlin.ir.IrElement
import org.jetbrains.kotlin.ir.backend.js.JsLoweredDeclarationOrigin
import org.jetbrains.kotlin.ir.declarations.*
import org.jetbrains.kotlin.ir.expressions.IrLoop
import org.jetbrains.kotlin.ir.types.isUnit
import org.jetbrains.kotlin.ir.util.fqNameWhenAvailable
import org.jetbrains.kotlin.ir.util.isEffectivelyExternal
import org.jetbrains.kotlin.ir.util.isInlined
@@ -254,8 +256,8 @@ class LegacyMemberNameGenerator(val scope: JsScope) {
val nameBuilder = StringBuilder()
// Handle names for special functions
if (declaration.isEqualsInheritedFromAny()) {
return scope.declareName("equals")
if (declaration.isMethodOfAny()) {
return scope.declareName(declarationName)
}
nameBuilder.append(declarationName)
@@ -272,9 +274,9 @@ class LegacyMemberNameGenerator(val scope: JsScope) {
joinTo(nameBuilder, "") { "_${it.type.asString()}" }
}
declaration.returnType.let {
// Return type is only used in signature for inline class types because
// Return type is only used in signature for inline class and Unit types because
// they are binary incompatible with supertypes.
if (it.isInlined()) {
if (it.isInlined() || it.isUnit()) {
nameBuilder.append("_ret$${it.asString()}")
}
}
+1
View File
@@ -4,6 +4,7 @@ open class A {
}
interface I {
@JsName("foo")
fun foo(): Any
}
@@ -1,4 +1,3 @@
// IGNORE_BACKEND: JS_IR
// EXPECTED_REACHABLE_NODES: 1292
var log = ""
+1
View File
@@ -11,5 +11,6 @@ object t {
}
object n {
@JsName("valueOf")
fun valueOf() = 42
}
@@ -4,6 +4,7 @@ package foo
class Counter {
var count: Int = 0
@JsName("inc")
public fun inc() {
count++
}
@@ -1,10 +1,12 @@
// EXPECTED_REACHABLE_NODES: 1301
public interface A {
@JsName("foo")
fun foo() {
}
}
public interface B : A {
@JsName("boo")
fun boo() {
}
}
+1
View File
@@ -253,6 +253,7 @@ public class Long internal constructor(
public override fun toDouble(): Double = toNumber()
// This method is used by `toString()`
@JsName("valueOf")
internal fun valueOf() = toDouble()
override fun equals(other: Any?): Boolean = other is Long && equalsLong(other)
@@ -44,6 +44,7 @@ public actual abstract class AbstractMutableCollection<E> protected actual const
}
}
@JsName("toJSON")
open fun toJSON(): Any = this.toArray()
}