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.

Compat Scala 2: Abstract override

See original GitHub issue
class Seq

trait IterableOnceOps {
  def toSeq: Seq = new Seq
}

trait IterableOps extends IterableOnceOps

trait SeqOps extends IterableOps {
  def toSeq: Seq
}

class Foo extends SeqOps

The code snippet above compiles with Scala2 but not Dotty:

-- Error: tests/allan/Test.scala:53:6 ------------------------------------------
53 |class Foo extends SeqOps
   |      ^
   | class Foo needs to be abstract, since def toSeq: => Seq is not defined 
one error found

This pattern is used in the 2.13 collection library

Issue Analytics

  • State:open
  • Created 5 years ago
  • Comments:13 (11 by maintainers)

github_iconTop GitHub Comments

2reactions
Jasper-Mcommented, Nov 16, 2020

Only discussion related to this that I can remember is https://contributors.scala-lang.org/t/ability-to-make-a-parents-concrete-method-abstract/1255

It’s also pointed out in that thread that Scala 2 already does the “Java thing” when it comes to abstract classes.

scala> class Baz { def foo: String = "string" }
class Baz

scala> trait Foo extends Baz{
     |   override def foo: String
     | }
trait Foo

scala> new Foo{}
val res5: Baz with Foo = $anon$1@4374e0

scala> abstract class Bar extends Baz{
     |   override def foo: String
     | }
class Bar

scala> new Bar{}
           ^
       error: object creation impossible. No implementation found in a subclass for deferred declaration
       override def foo: String (defined in class Bar)

In case that’s news to anyone.

0reactions
lrytzcommented, Nov 18, 2020

Scala 2 allows widening the type in an abstract override, but that seems a pretty obscure feature

scala> trait T { def f: String = "" }; trait U extends T { override def f: Object }
trait T
trait U
Read more comments on GitHub >

github_iconTop Results From Across the Web

Why is my abstract or overridden val null? | FAQ
Naturally when a val is overridden, it is not initialized more than once. So though x2 in the above example is seemingly defined...
Read more >
scala - Why is "abstract override" required not ... - Stack Overflow
It may not be abstract unless it is overridden by a member declared abstract and override The combination of abstract and override tells...
Read more >
Interface With Default Methods vs Abstract Class - Baeldung
Learn the differences between interfaces with default methods and abstract classes in Java.
Read more >
Chapter 8. Classes - Oracle Help Center
Any of C's superclasses has an abstract method declared with package access, and there exists no method that overrides the abstract method from...
Read more >
scala trait vs abstract class
Scala arrays are compatible with Scala sequences - we can pass an Array[T] where a Seq[T] is ... 2. 2022-10-23. 1. abstract class...
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