Commit 3b5f0c4
committed
Fix shadowing default method type parameters
When copying default methods to impls, rename type parameters of the
methods so that they won't be shadowed by the impl's type parameters.
For example, when copying this default method:
trait Iterator[iter, item, exn]:
map(self: iter, f: Fn(item) b / exn) Map[iter, item, b, exn]:
...
to impl:
impl[Iterator[iter, a, exn]] Iterator[Map[iter, a, b, exn], b, exn]:
...
If we naively copy, we get:
impl[Iterator[iter, a, exn]] Iterator[Map[iter, a, b, exn], b, exn]:
# iter -> Map[iter, a, b, exn]
# item -> b
# exn -> exn
map(self: Map[iter, a, b, exn], f: Fn(b) b / exn) Map[Map[iter, a, b, exn], b, b, exn]:
Map(iter = self, f = f)
Note that the return type of the callback argument (originally `b`) is
still `b`, but `b` is now bound in impl head.
To fix, we rename type parameters of copied methods by adding a `$copy`
suffix. New copied method:
impl[Iterator[iter, a, exn]] Iterator[Map[iter, a, b, exn], b, exn]:
# iter -> Map[iter, a, b, exn]
# item -> b
# exn -> exn
map(self: Map[iter, a, b, exn], f: Fn(b) b$copy / exn) Map[Map[iter, a, b, exn], b, b$copy, exn]:
Map(iter = self, f = f)
Fixes #275.1 parent 240bcf6 commit 3b5f0c4
2 files changed
+30
-0
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
530 | 530 | | |
531 | 531 | | |
532 | 532 | | |
| 533 | + | |
| 534 | + | |
| 535 | + | |
| 536 | + | |
| 537 | + | |
| 538 | + | |
| 539 | + | |
| 540 | + | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
| 550 | + | |
| 551 | + | |
| 552 | + | |
| 553 | + | |
533 | 554 | | |
534 | 555 | | |
535 | 556 | | |
| |||
539 | 560 | | |
540 | 561 | | |
541 | 562 | | |
| 563 | + | |
542 | 564 | | |
543 | 565 | | |
544 | 566 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
0 commit comments