Skip to content

Stack overflow while compiling a nested given #22145

Closed
@kyouko-taiga

Description

@kyouko-taiga

Compiler version

Scala compiler version 3.6.1 -- Copyright 2002-2024, LAMP/EPFL

Minimized code

import language.experimental.modularity

trait Collection:
  me =>

  type Self
  type Position
  type Element

  final class Slice(private[Collection] val base: Self, val start: Position, val end: Position):

    final def apply(p: Position): Element =
      require(base.isWithin(p, start, end), "position is out of bounds")
      base.apply(p)

  end Slice

  given Slice is Collection:

    type Position = me.Position
    type Element = me.Element

    extension (self: Self)
      def start: Position = self.start
      def end: Position = self.end
      def positionAfter(p: Position): Position = self.base.positionAfter(p)
      def apply(p: Position): Element = self.base.apply(p)

  end given

  extension (self: Self)

    def start: Position
    def end: Position
    def positionAfter(p: Position): Position
    def apply(p: Position): Element

  end extension

Output (click arrow to expand)

Note that the full stack trace is too long to report in the issue.

% scalac main.scala

Exception while compiling main.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 -Xno-enrich-error-messages.

 while compiling: <no file>
    during phase: parser
            mode: Mode()
 library version: version 2.13.15
compiler version: version 3.6.1
        settings: 

Exception in thread "main" java.lang.StackOverflowError
at scala.collection.mutable.Builder.sizeHint(Builder.scala:69)
at scala.collection.mutable.Builder.sizeHint$(Builder.scala:68)
at scala.collection.mutable.HashSet.addAll(HashSet.scala:94)
at scala.collection.mutable.HashSet$.from(HashSet.scala:31)
at scala.collection.mutable.HashSet$.from(HashSet.scala:407)
at scala.collection.IterableFactory.apply(Factory.scala:103)
at ...

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions