Skip to content

Cannot resolve reference to type member inherited through self type #21219

Open
@m8nmueller

Description

@m8nmueller

Compiler version

3.4.2

Minimized code

I tried to minimize as much as possible, but the crash is solved when either removing map or fold. If the two files are merged together, the compile still crashes, but it prints a type error before. I know that the self types of Stream and PullReaderStream do not work out, but that will be my business :).

File Stream.scala:

trait StreamOps[+T]:
  self: Family[T] =>

  type Family[+V] <: { type Result[+W] }
  type ThisStream[+V] <: StreamOps[V] { type Family[T] = self.Family[T] }

  def map[V](mapper: T => V): ThisStream[V]
  def fold(): Result[Unit]

trait Stream[+T] extends StreamOps[T]:
  override type Family[T] = Object { type Result[+V] =  V }

File PullStream.scala

trait PullReaderStream[+T] extends PullReaderStreamOps[T] with Stream[T]:
  override type ThisStream[+V] = PullReaderStream[V]

  override def map[V](mapper: T => V): PullReaderStream[V] =
    new PullReaderStream[V] {}

trait PullReaderStreamOps[+T] extends StreamOps[T]:
  self: Family[T] =>
  override type ThisStream[+V] <: PullReaderStreamOps[V] { type Family[T] = self.Family[T] }

  override def fold(): self.Result[Unit] = ???

Output (click arrow to expand)

  unhandled exception while running MegaPhase{crossVersionChecks, firstTransform, checkReentrant, elimPackagePrefixes, cookComments, checkLoopingImplicits, betaReduce, inlineVals, expandSAMs, elimRepeated, refchecks} on PullStream.scala

  An unhandled exception was thrown in the compiler.
  Please file a crash report here:
  https://github.com/scala/scala3/issues/new/choose
  For non-enriched exceptions, compile with -Yno-enrich-error-messages.

     while compiling: PullStream.scala
        during phase: MegaPhase{crossVersionChecks, firstTransform, checkReentrant, elimPackagePrefixes, cookComments, checkLoopingImplicits, betaReduce, inlineVals, expandSAMs, elimRepeated, refchecks}
                mode: Mode(ImplicitsEnabled)
     library version: version 2.13.12
    compiler version: version 3.4.2
            settings: 

cannot resolve reference to type ($anon.this : Object with PullReaderStream[V] {...}).Result
the classfile defining the type might be missing from the classpath

When merging the files, this is prefixed by:

-- [E058] Type Mismatch Error: Stream.scala:10:6 -------------------------------
10 |trait Stream[+T] extends StreamOps[T]:
   |      ^
   |illegal inheritance: self type Stream[T] of trait Stream does not conform to self type Stream.this.Family[T]
   |of parent trait StreamOps
   |
   | longer explanation available when compiling with `-explain`

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions