Skip to content

New proposal for extension methods #5114

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 56 commits into from
Dec 7, 2018
Merged
Changes from 1 commit
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
a708680
Establish companionship directly
odersky Oct 19, 2018
c78ee10
Compare two schemes how extensions could be used to encode typeclasses
odersky Sep 14, 2018
81a3cd5
New proposal for extension methods
odersky Sep 17, 2018
45ea7ae
Fix wording of translation rule
odersky Sep 17, 2018
04f4877
Fix example code
odersky Sep 17, 2018
e74fc4d
Address review comments
odersky Sep 17, 2018
dca503d
Another fix for example code
odersky Sep 17, 2018
54e6c85
Add missing type parameter
odersky Sep 17, 2018
75ea081
Add example file to pickling blacklist
odersky Sep 17, 2018
fdfe2f4
Parsing and pretty-printing of extension methods
odersky Sep 17, 2018
61b89c8
Fixes to code and syntax
odersky Sep 18, 2018
4b7121c
More fixes to doc
odersky Sep 18, 2018
85efcb4
Switch to prefix type arguments
odersky Sep 18, 2018
e88c3a8
Change syntax to "this modifier" scheme
odersky Sep 26, 2018
328140b
Parsing and pretty-printing for "this as modifier" scheme
odersky Sep 26, 2018
9b4dc40
Dotty docs for "this as modifier" scheme
odersky Sep 26, 2018
e3ad509
Fix rebase breakage
odersky Sep 26, 2018
93bedf5
Make extension objects eligible for implicit search
odersky Sep 27, 2018
6e224d8
Handle extension methods in implicit search
odersky Sep 27, 2018
e7c68ef
Avoid attachments to communicate extension method applications
odersky Sep 27, 2018
4481174
Avoid eta-expanding partially applied extension methods
odersky Sep 27, 2018
4a97662
Add check file to test
odersky Sep 27, 2018
18029a9
Add extensions-methods to pickling blacklist
odersky Sep 27, 2018
46f1a5c
Handle extension method applications with explicit type arguments
odersky Sep 28, 2018
d45fd68
Represent PolyProto arguments as trees, not types
odersky Sep 28, 2018
91729bc
Refactorings and polishings
odersky Sep 28, 2018
708504b
Consider extension methods if they are in scope
odersky Sep 29, 2018
c87a4a0
Catch cyclic references when trying extension methods
odersky Sep 29, 2018
6d0a157
Make findRef accessible outside of typedIdent
odersky Sep 30, 2018
1cf72c6
Add infrastructure to be able to search specifically for extension me…
odersky Sep 30, 2018
1a661db
Don't complete normal symbols when searching for an extension method
odersky Sep 30, 2018
6b31519
excluded -> exclusive
odersky Sep 30, 2018
601966f
Distinguish between required and excluded flags
odersky Sep 30, 2018
f25ec80
Fix rebase breakage
odersky Oct 12, 2018
981cb71
Update doc page to describe new resolution rules
odersky Oct 12, 2018
659e63f
Fix typo.
odersky Oct 12, 2018
c880d8e
Fixes for hasExtensionMethod
odersky Oct 14, 2018
5a4adf7
Clarify relationship to operators
odersky Oct 22, 2018
60aa019
Integrate extension methods docs in sidebar
odersky Oct 22, 2018
286a5d6
Update docs/docs/reference/extension-methods.md
buzden Oct 26, 2018
c19c240
Address review comments
odersky Oct 23, 2018
abddd42
Add disabled string interpolation test
odersky Nov 9, 2018
cb7a9d8
Revert: Dotty docs for "this as modifier" scheme
odersky Nov 17, 2018
f00cf7b
Revert: Parsing and pretty-printing for "this as modifier" scheme
odersky Nov 17, 2018
12cb7a1
Revert: Change syntax to "this modifier" scheme
odersky Nov 17, 2018
dd1db7a
Revert: Switch to prefix type arguments
odersky Nov 18, 2018
401931e
Extension methods with leading parameter list
odersky Nov 18, 2018
3d4366f
Handle positions in extension methods
odersky Nov 18, 2018
4c4c1e8
Update tests to use prefix parameter syntax for extension methods
odersky Nov 18, 2018
5f86ca0
Handle right-associative extension operators
odersky Nov 18, 2018
f97c6ff
Remove dead code in Parser
odersky Nov 21, 2018
7e2cd66
Avoid implicit objects that extend nothing
odersky Nov 26, 2018
cee2331
Implement reviewer suggestions
odersky Dec 4, 2018
9d7093c
Bring back xml-interpolation3 test
odersky Dec 4, 2018
3506192
Reject ambiguities between implicit conversions and extension methods
odersky Dec 4, 2018
49bae02
Reclassify test
odersky Dec 4, 2018
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
Prev Previous commit
Next Next commit
Revert: Switch to prefix type arguments
(reverted from commit d6ba157)
  • Loading branch information
odersky committed Dec 5, 2018
commit dd1db7acf5cc594fb209a188e27e053eed4fdf7a
4 changes: 1 addition & 3 deletions docs/docs/reference/extension-methods.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ def circumference(c: Circle): Double = c.radius * math.Pi * 2
assert(circle.circumference == CircleOps.circumference(circle))
```



### Translation of Calls to Extension Methods

When is an extension method considered? There are two possibilities. The first (and recommended one) is by defining the extension method as a member of an implicit value. The method can then be used as an extension method wherever the implicit value is applicable. The second possibility is by making the extension method itself visible under a simple name, typically by importing it. As an example, consider an extension method `longestStrings` on `String`. We can either define it like this:
Expand Down Expand Up @@ -175,7 +173,7 @@ that problem, it is recommended that the name of an extension method is
preceded by a space and is also followed by a space if there are more parameters
to come.

`### Extension Methods and TypeClasses
### Extension Methods and TypeClasses

The rules for expanding extension methods make sure that they work seamlessly with typeclasses. For instance, consider `SemiGroup` and `Monoid`.
```scala
Expand Down