fwcd / fwcd/kotlin-language-server

kotlin(OVERLOAD_RESOLUTION_AMBIGUITY) Java superclass ambiguity int/Integer

Open
#656 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Kotlin
Stars
2k
Forks
252
PR merge metrics
No merged PRs in 30d

Description

```kotlin
class StackCount: Object2IntOpenCustomHashMap(IntArrays.HASH_STRATEGY) {

fun change(stack: IntArray, count: Int): Int {
val newAmount = getOrDefault(stack, 0) + count
if (count == 0) return newAmount
if (newAmount == 0) removeInt(stack)
else put(stack, newAmount)
return newAmount
}

}
```

Screenshot

![Image](https://github.com/user-attachments/assets/e84f3978-2777-42cd-bdbf-8718ab12de01)

```log
Class 'StackCount' must override public open fun get(key: IntArray!): Int? defined in it.unimi.dsi.fastutil.objects.Object2IntMap because it inherits multiple interface methods of itkotlin(MANY_INTERFACES_MEMBER_NOT_IMPLEMENTED)
Class 'StackCount' must override public open fun remove(key: IntArray!): Int? defined in it.unimi.dsi.fastutil.objects.Object2IntMap because it inherits multiple interface methods of itkotlin(MANY_INTERFACES_MEMBER_NOT_IMPLEMENTED)
```

Screenshot

![Image](https://github.com/user-attachments/assets/7a0d0ee7-dedb-4510-9e9f-3930c8de6622)

```log
Overload resolution ambiguity:
public open fun getOrDefault(p0: Any!, p1: Int): Int defined in io.github.powercraft.item.StackCount
public open fun getOrDefault(p0: Any!, p1: Int!): Int! defined in io.github.powercraft.item.StackCount
public open fun getOrDefault(key: IntArray!, defaultValue: Int!): Int! defined in io.github.powercraft.item.StackCountkotlin(OVERLOAD_RESOLUTION_AMBIGUITY)
```

Screenshot

![Image](https://github.com/user-attachments/assets/7a1c7fd9-ccae-4dfa-8be2-8ded6c602807)

## Regarding getOrDefault: Educated guess: Integer/int merging into the same type in Kotlin. ##

![Image](https://github.com/user-attachments/assets/9aa27c48-2cc6-4c6b-bf63-47b8dec3da59)

This image from IntelliJ shows that it also struggles to resolve when I try to override as one takes and returns Integer (->Int!) and the other takes and returns int (->Int). But IntelliJ doesn't have an issue with it in the first place, though. So it just eats it without redefining `getOrDefault`. Would love if this LSP would also handle it that way.

## Regarding why I need to override `get` and `remove`, I have no clue. Both are deprecated.

But I could imagine it to be related to the same problem if multiple interfaces define slightly different methods (int vs Integer) and thus aren't fused automatically because the linter doesn't know which to assume. (again, IntelliJ doesn't even complain and the compiler compiles)

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.