# Feature Request Kotlin - call super infix functions as infix

**URL:** <https://discuss.kotlinlang.org/t/feature-request-kotlin-call-super-infix-functions-as-infix/21511>\
**Category:** Language Design\
**Created:** [April 12, 2021, 12:23pm UTC](https://discuss.kotlinlang.org/t/feature-request-kotlin-call-super-infix-functions-as-infix/21511 "2021-04-12T12:23:00Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![brymher](https://avatars.discourse-cdn.com/v4/letter/b/f17d59/32.png) [@brymher](https://discuss.kotlinlang.org/u/brymher)\
**Post date:** [April 12, 2021, 12:23pm UTC](https://discuss.kotlinlang.org/t/feature-request-kotlin-call-super-infix-functions-as-infix/21511/1 "2021-04-12T12:23:00Z")

</div>

Call of overridden super class infix method with infix syntax

```auto
class Foo{
    open infux fun showEmotion(emotion: String){
        println(emotion)
    }
}

class Bar : Foo {
    override fun showEmotion(emotion : String){
           super showEmotion emotion
    }
}

```

This is instead of

```auto
override fun showEmotion(emotion : String){
    super.showEmotion(emotion)
}

```

---

<div class="post-metadata">

**Author:** ![Wasabi375](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/wasabi375/32/4741_2.png) [@Wasabi375](https://discuss.kotlinlang.org/u/Wasabi375)\
**Post date:** [April 12, 2021, 12:42pm UTC](https://discuss.kotlinlang.org/t/feature-request-kotlin-call-super-infix-functions-as-infix/21511/2 "2021-04-12T12:42:37Z")

</div>

Why, what is the big advantage of that. Is this change important enough to offset the [minus 100 point rule](https://gist.github.com/stuartd/a100fb315f2e5ca9ed17551d8b538a60)? I don’t really think so.

---

<div class="post-metadata">

**Author:** ![brymher](https://avatars.discourse-cdn.com/v4/letter/b/f17d59/32.png) [@brymher](https://discuss.kotlinlang.org/u/brymher)\
**Post date:** [April 12, 2021, 1:06pm UTC](https://discuss.kotlinlang.org/t/feature-request-kotlin-call-super-infix-functions-as-infix/21511/3 "2021-04-12T13:06:14Z")

</div>

I agree doesn’t pass the rule. Felt it provided continuity with infix method syntax.

---

<div class="post-metadata">

**Author:** ![arocnies](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/arocnies/32/5143_2.png) [@arocnies](https://discuss.kotlinlang.org/u/arocnies)\
**Post date:** [April 12, 2021, 1:53pm UTC](https://discuss.kotlinlang.org/t/feature-request-kotlin-call-super-infix-functions-as-infix/21511/4 "2021-04-12T13:53:52Z")

</div>

`super` isn’t the same as a reference to `this`.  
The exact error is:

> ‘super’ is not an expression, it can only be used on the left-hand side of a dot (‘.’)

Super is a bit different from `this` in that it’s not an expression.

```kotlin
(super).anyFunction() // Doesn't work... even if the function is not infix

```

Since infix functions work with left-hand and right-hand expressions, using super on either side is the same as having `(super)` in parentheses as an expression.

Here’s a runnable (and editable ✏ ) example. Try uncommenting some of the lines to see what happens:

```run-kotlin
open class Base {
    open infix fun method(int: Int) = println("left=$this, right=$int")
    val instance = this
}

class Foo : Base() {
    init {
        //sampleStart
        (1 + 1) example (3 + 3)
        1 + 1 example 3 + 3
        
        this.method(4 + 1)
        this method 4 + 1
        (this) method (4 + 1)
        
        super.method(4 + 1)
        //super method 4 + 1 // <-- Try uncommenting this line
        //(super).method(4 + 1) // <-- Try uncommenting this line
        (this as Base) method 4 + 1
        
        instance method 4 + 1
        super.instance method 4 + 1
        //(super).instance // <-- Try uncommenting this line
        //sampleEnd
    }
}

infix fun Int.example(other: Int) = println("Example: left=$this, right=$other")

fun main() {
    Foo()
}

```

---

<div class="post-metadata">

**Author:** ![brymher](https://avatars.discourse-cdn.com/v4/letter/b/f17d59/32.png) [@brymher](https://discuss.kotlinlang.org/u/brymher)\
**Post date:** [April 12, 2021, 2:11pm UTC](https://discuss.kotlinlang.org/t/feature-request-kotlin-call-super-infix-functions-as-infix/21511/5 "2021-04-12T14:11:28Z")

</div>

> [@arocnies](#):
>

Yeah, I agree super is not an expression. My view is to enable consistency with infix method syntax  
`this infixMethod arguments` works  
then why wouldn’t  
`super infixMethodName argument` work

In my example the super `showEmotion` can’t be used in the overridden method with infix syntax observed thus it can only be called as `super.showEmotion(/*arguments*/) `

I get your point though.

---

<div class="post-metadata">

**Author:** ![arocnies](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/arocnies/32/5143_2.png) [@arocnies](https://discuss.kotlinlang.org/u/arocnies)\
**Post date:** [April 12, 2021, 3:21pm UTC](https://discuss.kotlinlang.org/t/feature-request-kotlin-call-super-infix-functions-as-infix/21511/6 "2021-04-12T15:21:23Z")

</div>

Yeah it could be nice for constancy–it’s a good thing to point out at least 👍

I more so posted my stuff for future readers. Since the cost/benefit ratio may be low, I figure either: this request might sit idle (if it’s the only use-case and not considered a bug). Or in the future something changes with the compiler or language features that changes use-cases or defines the correct behavior.
