@@ -20,7 +20,27 @@ abstract class TypeScriptToKotlinBase(
20
20
21
21
open fun addFunction (symbol : Symbol ? , name : String , callSignature : KtCallSignature , extendsType : KtType ? = null, needsNoImpl : Boolean = true, additionalAnnotations : List <KtAnnotation > = listOf(), isOverride : Boolean = false, isOperator : Boolean = false) {
22
22
val annotations = defaultAnnotations + additionalAnnotations
23
- addDeclaration(symbol, KtFunction (KtName (name), callSignature, extendsType?.let { KtHeritageType (it) }, annotations, needsNoImpl = needsNoImpl, isOverride = isOverride, hasOpenModifier = hasMembersOpenModifier, isOperator = isOperator))
23
+ var actualIsOverride = isOverride
24
+ val overrideCallSignature = if (" hashCode" == name && callSignature.params.isEmpty()) {
25
+ actualIsOverride = true
26
+ // force hashCode to return an Int so it will compile
27
+ callSignature.copy(returnType = callSignature.returnType.copy(type = KtType (INT )))
28
+ } else if (" toString" == name && callSignature.params.isEmpty()) {
29
+ actualIsOverride = true
30
+ // force toString to return a String so it will compile
31
+ callSignature.copy(returnType = callSignature.returnType.copy(type = KtType (STRING )))
32
+ } else if (" equals" == name && callSignature.params.size == 1 && callSignature.params[0 ].type.type.qualifiedName == ANY ) {
33
+ actualIsOverride = true
34
+ callSignature.copy(
35
+ // force equals to take Any? (instead of Any) so that it overrides
36
+ params = callSignature.params.map { it.copy(type = it.type.copy(type = KtType (ANY , isNullable = true ))) },
37
+ // force equals to return a Boolean so it will compile
38
+ returnType = callSignature.returnType.copy(type = KtType (BOOLEAN )))
39
+ } else {
40
+ callSignature
41
+ }
42
+ val heritageType = extendsType?.let { KtHeritageType (it) }
43
+ addDeclaration(symbol, KtFunction (KtName (name), overrideCallSignature, heritageType, annotations, needsNoImpl, actualIsOverride, hasMembersOpenModifier, isOperator))
24
44
}
25
45
26
46
protected fun addDeclaration (symbol : Symbol ? , declaration : KtMember ) {
0 commit comments