question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Method in trait not a legal implementation in inheriting class (V2)

See original GitHub issue
package collection

trait Map[K, +V] extends MapOps[K, V, Map]

trait MapOps[K, +V, +CC[_, _]] {
  def collect[K2, V2](pf: PartialFunction[(K, V), (K2, V2)]): CC[K2, V2] = ???
}

trait SortedMapOps[K, +V, +CC[X, Y] <: Map[X, Y] with SortedMapOps[X, Y, CC]]
  extends MapOps[K, V, Map]

trait StrictOptimizedMapOps[K, +V, +CC[_, _]] extends MapOps[K, V, CC] {

  override def collect[K2, V2](pf: PartialFunction[(K, V), (K2, V2)]): CC[K2, V2] = ???
}

trait StrictOptimizedSortedMapOps[K, +V, +CC[X, Y] <: Map[X, Y] with SortedMapOps[X, Y, CC]]
  extends SortedMapOps[K, V, CC] with StrictOptimizedMapOps[K, V, Map]


package immutable {
  trait Map[K, +V] extends collection.Map[K, V] with MapOps[K, V, Map]

  trait MapOps[K, +V, +CC[X, +Y] <: MapOps[X, Y, CC]] extends collection.MapOps[K, V, CC]

  trait SortedMapOps[K, +V, +CC[X, +Y] <: Map[X, Y] with SortedMapOps[X, Y, CC]]
    extends MapOps[K, V, Map] with collection.SortedMapOps[K, V, CC]

  class TreeMap[K, +V] extends Map[K, V] with SortedMapOps[K, V, TreeMap]
    with StrictOptimizedSortedMapOps[K, V, TreeMap]
}
-- Error: tests/allan/Test.scala:86:8 ------------------------------------------
86 |  class TreeMap[K, +V] extends Map[K, V] with SortedMapOps[K, V, TreeMap]
   |        ^
   |method collect in trait StrictOptimizedMapOps is not a legal implementation of `collect` in class TreeMap
   |  its type             [K2, V2](pf: PartialFunction[(K, V), (K2, V2)]): collection.Map[K2, V2]
   |  does not conform to  [K2, V2]
   |  (pf: PartialFunction[(K, V), (K2, V2)]): collection.immutable.Map[K2, V2]
one error found

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
smartercommented, Jul 26, 2018

Opened https://github.com/scala/bug/issues/11042 to track a related soundness bug in scalac.

0reactions
Blaisorbladecommented, Aug 2, 2018

Closing as the bug was not in Dotty and the library was fixed — @allanrenucci correct me if I’m wrong.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Implementing an abstract method with a trait, inconsistent ...
The real key to the power of traits is the way in which the compiler treats them in an inheriting class. Traits are...
Read more >
Scala Traits vs. Abstract Classes - Baeldung
Traits are used to group methods for a given behavior. Just like abstract classes they can have fully defined and not implement methods....
Read more >
The Practical Difference Between Abstract Classes and Traits ...
This short article will compare abstract classes and traits as means of inheritance.
Read more >
Are default trait method implementations as reusable ... - Reddit
In The Book, Ch 17.1 argues against the use of inheritance. It states that inheritance is good for two things: 1. Reuse code...
Read more >
Classes & Objects | Scala 2.13
Finally, a template is not allowed to contain two methods (directly defined or inherited) with the same name which both define default arguments....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found