Skip to content

Mixin trait using abstract member of parent class won't compile when they reside in different packages #12249

@Naitreey

Description

@Naitreey

The bug was firstly asked on stackoverflow. Here is the reference post. Here's a gist to reproduce the issue, created by @DmytroMitin.
Tested on Scala 2.12.11, 2.13.3, 2.13.4.

reproduction steps

  1. In file A.scala, we have

    package mixintest.a
    abstract class A {
      protected val x: Int
    }
  2. In file B.scala, we have

    package mixintest.b
    import mixintest.a.A
    trait B extends A {
      println(x)
    }
  3. In file C.scala, we have

    package mixintest.c
    import mixintest.a.A
    import mixintest.b.B
    case class C(override protected val x: Int) extends A with B
  4. build.sbt

    ThisBuild / scalaVersion := "2.13.3"
  5. run compile in sbt shell, emitting the following error:

sbt:scala> compile
[info] Compiling 3 Scala sources to /Users/naitree/Documents/try/scala/target/scala-2.13/classes ...
[error] /Users/naitree/Documents/try/scala/src/main/scala/C.scala:4:12: Member value x of mixin trait B is missing a concrete super implementation.
[error] case class C(override protected val x: Int) extends A with B
[error]            ^
[error] one error found
[error] (Compile / compileIncremental) Compilation failed
[error] Total time: 0 s, completed Nov 26, 2020, 5:13:32 PM
sbt:scala>

problem

When A, B, C are defined in the same package, it compiles successfully. But it won't compile if they reside in different packages.

By the way, I can workaround the bug, by re-declaring the abstrat member in B trait:

package mixintest.b
import mixintest.a.A
trait B extends A {
  protected val x: Int  // workaround
  println(x)
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions