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

Compiler crash on export/typing of typeclass using context functions #15181

Closed
WojciechMazur opened this issue May 13, 2022 · 1 comment · Fixed by #15217
Closed

Compiler crash on export/typing of typeclass using context functions #15181

WojciechMazur opened this issue May 13, 2022 · 1 comment · Fixed by #15217
Assignees
Labels
itype:bug itype:crash regression This worked in a previous version but doesn't anymore
Milestone

Comments

@WojciechMazur
Copy link
Contributor

WojciechMazur commented May 13, 2022

Compiler version

3.1.2
Fails with nightly (13.05.2022)
Works with 3.1.1

First bad commit f50b55c

Minimized code

Based on https://github.com/jcouyang/meow/blob/22e5a47682ec15861f45d71692f640bd218e0044/src/main/scala/Semigroup.scala#L24 and
https://github.com/jcouyang/meow/blob/9513eb8b314c2256d0e3b95e834ebee86078484c/src/main/scala/Prelude.scala

//> using scala "3.1.2"

object prelude:
  export Semigroup.*

trait Semigroup[A]:
  def scombine(x: A, y: A): A

object Semigroup:
  def scombine[A](x: A, y: A) = (s: Semigroup[A]) ?=> s.scombine(x,y)

Output (click arrow to expand)

exception while typing final def scombine[A](x: A, y: A): (Semigroup[A]) ?=> A = Semigroup.scombine[A](x, y) of class class dotty.tools.dotc.ast.Trees$DefDef # -1
exception while typing @SourceFile("test.scala") final module class prelude() extends Object() {
  private def writeReplace(): AnyRef = new scala.runtime.ModuleSerializationProxy(classOf[prelude.type])
  final def scombine[A](x: A, y: A): (Semigroup[A]) ?=> A = Semigroup.scombine[A](x, y)
} of class class dotty.tools.dotc.ast.Trees$TypeDef # -1
exception while typing package <empty> {
  final lazy module val prelude: prelude = new prelude()
  @SourceFile("test.scala") final module class prelude() extends Object() {
    private def writeReplace(): AnyRef = new scala.runtime.ModuleSerializationProxy(classOf[prelude.type])
    final def scombine[A](x: A, y: A): (Semigroup[A]) ?=> A = Semigroup.scombine[A](x, y)
  }
  @SourceFile("test.scala") trait Semigroup[A]() extends Object {
    private type A
    def scombine(x: A, y: A): A
  }
  final lazy module val Semigroup: Semigroup = new Semigroup()
  @SourceFile("test.scala") final module class Semigroup() extends Object() {
    private def writeReplace(): AnyRef = new scala.runtime.ModuleSerializationProxy(classOf[Semigroup.type])
    @ContextResultCount(1) def scombine[A](x: A, y: A): (Semigroup[A]) ?=> A = 
      {
        def $anonfun(using s: Semigroup[A]): A = s.scombine(x, y)
        closure($anonfun)
      }
  }
} of class class dotty.tools.dotc.ast.Trees$PackageDef # -1
exception occurred while compiling test.scala
java.lang.AssertionError: assertion failed while compiling test.scala
Exception in thread "main" java.lang.AssertionError: assertion failed
        at scala.runtime.Scala3RunTime$.assertFailed(Scala3RunTime.scala:11)
        at dotty.tools.dotc.transform.Erasure$Boxing$.adaptToType(Erasure.scala:388)
        at dotty.tools.dotc.transform.Erasure$Typer.adapt(Erasure.scala:1041)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2994)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2998)
        at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:3114)
        at dotty.tools.dotc.typer.Typer.$anonfun$48(Typer.scala:2302)
        at dotty.tools.dotc.typer.PrepareInlineable$.dropInlineIfError(PrepareInlineable.scala:248)
        at dotty.tools.dotc.typer.Typer.typedDefDef(Typer.scala:2302)
        at dotty.tools.dotc.transform.Erasure$Typer.typedDefDef(Erasure.scala:931)
        at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:2841)
        at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2928)
        at dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:126)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2994)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2998)
        at dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:3020)
        at dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:3070)
        at dotty.tools.dotc.transform.Erasure$Typer.typedStats(Erasure.scala:1029)
        at dotty.tools.dotc.typer.Typer.typedClassDef(Typer.scala:2507)
        at dotty.tools.dotc.transform.Erasure$Typer.typedClassDef(Erasure.scala:1019)
        at dotty.tools.dotc.typer.Typer.typedTypeOrClassDef$1(Typer.scala:2853)
        at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:2857)
        at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2928)
        at dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:126)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2994)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2998)
        at dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:3020)
        at dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:3070)
        at dotty.tools.dotc.transform.Erasure$Typer.typedStats(Erasure.scala:1029)
        at dotty.tools.dotc.typer.Typer.typedPackageDef(Typer.scala:2636)
        at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:2898)
        at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2929)
        at dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:126)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2994)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2998)
        at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:3114)
        at dotty.tools.dotc.transform.Erasure.run(Erasure.scala:144)
        at dotty.tools.dotc.core.Phases$Phase.runOn$$anonfun$1(Phases.scala:311)
        at scala.collection.immutable.List.map(List.scala:246)
        at dotty.tools.dotc.core.Phases$Phase.runOn(Phases.scala:312)
        at dotty.tools.dotc.Run.runPhases$1$$anonfun$1(Run.scala:225)
        at scala.runtime.function.JProcedure1.apply(JProcedure1.java:15)
        at scala.runtime.function.JProcedure1.apply(JProcedure1.java:10)
        at scala.collection.ArrayOps$.foreach$extension(ArrayOps.scala:1328)
        at dotty.tools.dotc.Run.runPhases$1(Run.scala:236)
        at dotty.tools.dotc.Run.compileUnits$$anonfun$1(Run.scala:244)
        at dotty.tools.dotc.Run.compileUnits$$anonfun$adapted$1(Run.scala:253)
        at dotty.tools.dotc.util.Stats$.maybeMonitored(Stats.scala:68)
        at dotty.tools.dotc.Run.compileUnits(Run.scala:253)
        at dotty.tools.dotc.Run.compileSources(Run.scala:186)
        at dotty.tools.dotc.Run.compile(Run.scala:170)
        at dotty.tools.dotc.Driver.doCompile(Driver.scala:35)
        at dotty.tools.dotc.Driver.process(Driver.scala:195)
        at dotty.tools.dotc.Driver.process(Driver.scala:163)
        at dotty.tools.dotc.Driver.process(Driver.scala:175)
        at dotty.tools.dotc.Driver.main(Driver.scala:205)
        at dotty.tools.dotc.Main.main(Main.scala)
@WojciechMazur WojciechMazur added itype:bug itype:crash stat:needs triage Every issue needs to have an "area" and "itype" label labels May 13, 2022
@griggt
Copy link
Collaborator

griggt commented May 13, 2022

Started crashing with f50b55c.

@bishabosha bishabosha removed the stat:needs triage Every issue needs to have an "area" and "itype" label label May 14, 2022
@prolativ prolativ added the regression This worked in a previous version but doesn't anymore label May 16, 2022
@Kordyjan Kordyjan added this to the 3.1.3 milestone May 16, 2022
odersky added a commit to dotty-staging/dotty that referenced this issue May 18, 2022
Kordyjan pushed a commit to dotty-staging/dotty that referenced this issue May 31, 2022
Kordyjan pushed a commit to dotty-staging/dotty that referenced this issue May 31, 2022
bishabosha pushed a commit to dotty-staging/dotty that referenced this issue Oct 18, 2022
@Kordyjan Kordyjan modified the milestones: 3.1.3, 3.2.0 Aug 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
itype:bug itype:crash regression This worked in a previous version but doesn't anymore
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants