# Implementation of extensions doesn't match expectation or documentation

**URL:** <https://contributors.scala-lang.org/t/implementation-of-extensions-doesnt-match-expectation-or-documentation/6307>\
**Category:** Language Design\
**Created:** [September 5, 2023, 6:07pm UTC](https://contributors.scala-lang.org/t/implementation-of-extensions-doesnt-match-expectation-or-documentation/6307 "2023-09-05T18:07:23Z")\
**Posts on this page:** 1\
**Showing post:** 16

<div class="post-metadata">

**Author:** ![dbingham](https://contributors.scala-lang.org/user_avatar/contributors.scala-lang.org/dbingham/32/2787_2.png) [@dbingham](https://contributors.scala-lang.org/u/dbingham)\
**Post date:** [September 8, 2023, 8:03pm UTC](https://contributors.scala-lang.org/t/implementation-of-extensions-doesnt-match-expectation-or-documentation/6307/16 "2023-09-08T20:03:23Z")

</div>

Sorry for replying to myself here, but I’ve been reading more of the links provided and re-reading the ones I had found before. I cannot escape the idea that _everyone_ seems to believe that extensions extend a _type_. For one it is [in the documentation](https://docs.scala-lang.org/scala3/reference/contextual/extension-methods.html):

> Extension methods allow one to add methods to a type after the type is defined.

It is mentioned in [the proposal from fkowal](https://contributors.scala-lang.org/t/improve-readability-learnability-of-extension-methods/3787):

> It builds on the knowledge/expectations of how class/trait inheritance works.  
> …  
> This trait also extends the type T with additional extension methods

[and the one from odersky](https://contributors.scala-lang.org/t/proposal-to-add-extension-methods-to-the-language/2945):

> Extension methods are a more straightforward and simpler alternative to implicit classes.

In fact, as som-snytt points out, szeiger raised the exact same issue I raised here, without a resolution that I can see in the thread.

The concept is also raised [in PRs](https://github.com/lampepfl/dotty/pull/4153):

> The aim of this proposal is to
> 
> - make typeclasses easy and pleasant to use.
> - remove the rift between standard class hierarchies and typeclass hierarchies. Both should be written in the same way and it should be possible to mix both styles and move fluidly between them.
> - in conjunction with opaque types, replace the lower-level constructs of value classes and implicit classes.

All _type_ based goals. These same goals are referenced from [LukaCJB’s proposal](https://github.com/LukaJCB/typeclass-proposal) which led to [odersky’s PR#5114](https://github.com/lampepfl/dotty/pull/5114).

And throughout _all_ of the threads on this topic both in the forums here, in PRs, and everywhere that I can find, there is abundant discussion of the handling of `this`. Which seems to imply a strong belief that the `type` definition is the thing being extended. I realize that the final syntax dropped references to `this`, but what I’m trying to point out is the community understanding of what `extension` means.

> [@som-snytt](#):
>
> I think the spec need only specify that “extension methods” are an extension to method application syntax. It has nothing to do with “extending a type”.

I have seen assertions to this effect elsewhere as well. But based on what seems to me to be abundant evidence that extensions are seen as extending a type, this feels like wishful thinking, not a reflection of the reality “on the ground” so-to-speak. Which is exactly why this topic keeps coming up, multiple bugs are filed, and confusion rules the day with regard to what is meant with this new construct. Everyone thinks it is about _types_ but the implementation thinks it is about _method application_. And therein lies the bug.

If our goal in language design is to remove friction and enable efficiency among developers using the language, subverting expectations and insisting everyone is wrong is a bug with regard to that goal.

And as we’re discovering, the place where the “bug” is best seen is in the divergent handling of right-associative methods.

Given all this, I think it would very much be a step in the wrong direction to double down on this conflicted definition of `extension`, remove capabilities from classes, and force the language into a different pattern. That’s a very heavy handed “fix” for the implementation of `extension` failing to match expectations.

---

_[View the full topic](https://contributors.scala-lang.org/t/implementation-of-extensions-doesnt-match-expectation-or-documentation/6307)._
