Skip to content

Test demonstrating extension method shorthands #6339

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 19, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions tests/run/extmethods2.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
object Test extends App {

class TC

implied StringListOps given TC {
type T = List[String]
def (x: T) foo (y: T) = (x ++ y, the[TC])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's an interesting trick, but I'm afraid that it'll make signature information less readable in error messages and in the IDE (e.g. if I'm writing a.foo(, then a signature popup will tell me that an argument of type T is expected), and dealiasing all the time before showing type information is likely to be even less readable in general.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, in practice it would probably be named This or Self or Left, not T. And of course we should have defined foo like this:

def (x: T) foo (y: List[String]) = ...

Then the signature popup gives you the right info again.

def (x: T) bar (y: Int) = (x(0)(y), the[TC])
}

def test given TC = {
assert(List("abc").foo(List("def"))._1 == List("abc", "def"))
assert(List("abc").bar(2)._1 == 'c')
}

test given TC()
}