Skip to content

Commit 52f80e9

Browse files
committed
Fix weird issue with overriding equals
1 parent 5207d57 commit 52f80e9

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

server/src/main/kotlin/org/javacs/kt/overridemembers/OverrideMembers.kt

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import org.jetbrains.kotlin.js.resolve.diagnostics.findPsi
2626
import org.jetbrains.kotlin.psi.psiUtil.endOffset
2727
import org.jetbrains.kotlin.psi.psiUtil.isAbstract
2828
import org.jetbrains.kotlin.psi.psiUtil.startOffset
29+
import org.jetbrains.kotlin.psi.psiUtil.unwrapNullability
2930
import org.jetbrains.kotlin.types.TypeProjection
3031
import org.jetbrains.kotlin.types.KotlinType
3132
import org.jetbrains.kotlin.lexer.KtTokens
@@ -188,32 +189,34 @@ private fun parametersMatch(
188189
): Boolean {
189190
if (function.valueParameters.size == functionDescriptor.valueParameters.size) {
190191
for (index in 0 until function.valueParameters.size) {
191-
LOG.info("Method: {} {} - {} {}", function.valueParameters[index].name, functionDescriptor.valueParameters[index].name.asString(), function.valueParameters[index].typeReference?.typeName(), functionDescriptor.valueParameters[index]
192+
LOG.info("Method: {} {} - {} {}", function.valueParameters[index].name, functionDescriptor.valueParameters[index].name.asString(), function.valueParameters[index].typeReference?.typeElement?.unwrapNullability()?.name, functionDescriptor.valueParameters[index]
192193
.type
193194
.unwrappedType()
194195
.toString())
195196
if (function.valueParameters[index].name !=
196-
functionDescriptor.valueParameters[index].name.asString()
197+
functionDescriptor.valueParameters[index].name.asString()
197198
) {
198199
return false
199200
} else if (function.valueParameters[index].typeReference?.typeName() !=
200201
functionDescriptor.valueParameters[index]
201202
.type
202203
.unwrappedType()
203-
.toString()
204+
.toString() && function.valueParameters[index].typeReference?.typeName() != null
204205
) {
206+
// Any and Any? seems to be null for Kt* psi objects for some reason? At least for equals
207+
// TODO: look further into this
208+
205209
// Note: Since we treat Java overrides as non nullable by default, the above test
206210
// will fail when the user has made the type nullable.
207211
// TODO: look into this
208-
// TODO: look into the weird issue with equals...
209212
return false
210213
}
211214
}
212215

213216
if (function.typeParameters.size == functionDescriptor.typeParameters.size) {
214217
for (index in 0 until function.typeParameters.size) {
215218
if (function.typeParameters[index].variance !=
216-
functionDescriptor.typeParameters[index].variance
219+
functionDescriptor.typeParameters[index].variance
217220
) {
218221
return false
219222
}

0 commit comments

Comments
 (0)