Skip to content

Commit ca35cd6

Browse files
committed
Allow extension re-use through automatically inserted forwarders
1 parent 4344eee commit ca35cd6

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

tests/pos/typeclass-encoding3.scala

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -512,8 +512,11 @@ object hasLength {
512512
common def unit: This
513513
}
514514
515-
extension IntOps for Int : Monoid {
515+
extension IntSemiGroup for Int : SemiGroup {
516516
def add(that: Int) = this + that
517+
}
518+
519+
extension IntMonoid for Int : Monoid {
517520
common def unit = 0
518521
}
519522
@@ -567,13 +570,22 @@ object semiGroups {
567570
}
568571
}
569572

570-
implicit object IntOps extends Monoid.Common {
573+
implicit object IntSemiGroup extends SemiGroup.Common { self =>
574+
type This = Int
575+
type Instance = SemiGroup { val `common`: self.type }
576+
def inject($this: Int) = new SemiGroup {
577+
val `common`: self.type = self
578+
def add(that: Int): Int = $this + that
579+
}
580+
}
581+
582+
implicit object IntMonoid extends Monoid.Common { self =>
571583
type This = Int
572-
type Instance = Monoid { val `common`: IntOps.type }
584+
type Instance = Monoid { val `common`: self.type }
573585
def unit: Int = 0
574586
def inject($this: Int) = new Monoid {
575-
val `common`: IntOps.this.type = IntOps.this
576-
def add(that: This): This = $this + that
587+
val `common`: self.type = self
588+
def add(that: This): This = IntSemiGroup.inject($this).add(that)
577589
}
578590
}
579591

0 commit comments

Comments
 (0)