Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stack overflow while compiling a nested given #22145

Open
kyouko-taiga opened this issue Dec 5, 2024 · 2 comments · May be fixed by #22361
Open

Stack overflow while compiling a nested given #22145

kyouko-taiga opened this issue Dec 5, 2024 · 2 comments · May be fixed by #22361
Assignees
Labels

Comments

@kyouko-taiga
Copy link
Contributor

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 ...

@kyouko-taiga kyouko-taiga added itype:bug itype:crash stat:needs triage Every issue needs to have an "area" and "itype" label labels Dec 5, 2024
@Gedochao Gedochao added area:experimental:modularity Issues related to the modularity extension. area:parser and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels Dec 6, 2024
@mbovel
Copy link
Member

mbovel commented Jan 12, 2025

This issue was picked for the Scala Issue Spree of tomorrow, Monday, January 13th. @natsukagami and I will be working on it.

@mbovel
Copy link
Member

mbovel commented Jan 13, 2025

Minimized:

trait Collection:
  val base: Collection = ???
  base.foo()

  object O extends Collection:
    def foo(): Int = ???

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants