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

Missing context bound implicit crashes compiler under -source:3.4-migration #19506

Closed
WojciechMazur opened this issue Jan 22, 2024 · 2 comments · Fixed by #19512
Closed

Missing context bound implicit crashes compiler under -source:3.4-migration #19506

WojciechMazur opened this issue Jan 22, 2024 · 2 comments · Fixed by #19512
Assignees
Labels
area:typer itype:bug itype:crash regression This worked in a previous version but doesn't anymore

Comments

@WojciechMazur
Copy link
Contributor

New regression found in Open CB for com-lihaoyi/upickle
It was not found in the maintained CommunityBuild, because Open CB might automatically add -source:3.x-migration flags.

The issue exists only when we combine -source:3.4-migration, method with context bound and at least 1 default method argument.

Compiler version

Last good release: 3.4.0-RC1-bin-20240109-91db06a-NIGHTLY
First bad release: 3.4.0-RC1-bin-20240112-c50f2ff-NIGHTLY
Bisect points to 13a71ef

Minimized code

//> using options "-source:3.4-migration",

trait Reader[T]
def read[T: Reader](s: String, trace: Boolean = false): T = ???

@main def Test = read[Object]("") // crash 

Output (click arrow to expand)

exception occurred while typechecking /Users/wmazur/projects/dotty/bisect/main.scala

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

     while compiling: /Users/wmazur/projects/dotty/bisect/main.scala
        during phase: typer
                mode: Mode(ImplicitsEnabled)
     library version: version 2.13.12
    compiler version: version 3.4.0-RC1-bin-SNAPSHOT-git-13a71ef
            settings: -classpath /Users/wmazur/.ivy2/local/org.scala-lang/scala3-library_3/3.4.0-RC1-bin-SNAPSHOT/jars/scala3-library_3.jar:/Users/wmazur/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/org/scala-lang/scala-library/2.13.12/scala-library-2.13.12.jar -d /Users/wmazur/projects/dotty/bisect/.scala-build/bisect_1983f628ca-3fe1fc2157/classes/main -java-output-version 17 -source 3.4-migration -sourceroot /Users/wmazur/projects/dotty/bisect

Exception in thread "main" java.util.NoSuchElementException: head of empty list
        at scala.collection.immutable.Nil$.head(List.scala:662)
        at scala.collection.immutable.Nil$.head(List.scala:661)
        at dotty.tools.dotc.typer.Migrations.contextBoundParams(Migrations.scala:115)
        at dotty.tools.dotc.typer.Migrations.contextBoundParams$(Migrations.scala:28)
        at dotty.tools.dotc.typer.Typer.contextBoundParams(Typer.scala:120)
        at dotty.tools.dotc.typer.Typer.adaptToArgs$1(Typer.scala:3776)
        at dotty.tools.dotc.typer.Typer.adapt1(Typer.scala:4360)
        at dotty.tools.dotc.typer.Typer.adapt(Typer.scala:3679)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3275)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3279)
        at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:3391)
        at dotty.tools.dotc.typer.Applications.realApply$1(Applications.scala:956)
        at dotty.tools.dotc.typer.Applications.typedApply(Applications.scala:1116)
        at dotty.tools.dotc.typer.Applications.typedApply$(Applications.scala:350)
        at dotty.tools.dotc.typer.Typer.typedApply(Typer.scala:120)
        at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:3114)
        at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3198)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3275)
        at dotty.tools.dotc.typer.Typer.addImplicitArgs$1(Typer.scala:3911)
        at dotty.tools.dotc.typer.Typer.adaptNoArgsImplicitMethod$1(Typer.scala:3929)
        at dotty.tools.dotc.typer.Typer.adaptNoArgs$1(Typer.scala:4129)
        at dotty.tools.dotc.typer.Typer.adapt1(Typer.scala:4365)
        at dotty.tools.dotc.typer.Typer.adapt(Typer.scala:3679)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3275)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3279)
        at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:3391)
        at dotty.tools.dotc.typer.Namer.typedAheadExpr$$anonfun$1(Namer.scala:1670)
        at dotty.tools.dotc.typer.Namer.typedAhead(Namer.scala:1660)
        at dotty.tools.dotc.typer.Namer.typedAheadExpr(Namer.scala:1670)
        at dotty.tools.dotc.typer.Namer.typedAheadRhs$1$$anonfun$1(Namer.scala:1932)
        at dotty.tools.dotc.inlines.PrepareInlineable$.dropInlineIfError(PrepareInlineable.scala:256)
        at dotty.tools.dotc.typer.Namer.typedAheadRhs$1(Namer.scala:1932)
        at dotty.tools.dotc.typer.Namer.rhsType$1(Namer.scala:1940)
        at dotty.tools.dotc.typer.Namer.cookedRhsType$1(Namer.scala:1958)
        at dotty.tools.dotc.typer.Namer.lhsType$1(Namer.scala:1959)
        at dotty.tools.dotc.typer.Namer.inferredResultType(Namer.scala:1970)
        at dotty.tools.dotc.typer.Namer.inferredType$1(Namer.scala:1708)
        at dotty.tools.dotc.typer.Namer.valOrDefDefSig(Namer.scala:1714)
        at dotty.tools.dotc.typer.Namer.defDefSig(Namer.scala:1812)
        at dotty.tools.dotc.typer.Namer$Completer.typeSig(Namer.scala:800)
        at dotty.tools.dotc.typer.Namer$Completer.completeInCreationContext(Namer.scala:943)
        at dotty.tools.dotc.typer.Namer$Completer.complete(Namer.scala:823)
        at dotty.tools.dotc.core.SymDenotations$SymDenotation.completeFrom(SymDenotations.scala:174)
        at dotty.tools.dotc.core.Denotations$Denotation.completeInfo$1(Denotations.scala:189)
        at dotty.tools.dotc.core.Denotations$Denotation.info(Denotations.scala:191)
        at dotty.tools.dotc.core.SymDenotations$SymDenotation.ensureCompleted(SymDenotations.scala:393)
        at dotty.tools.dotc.typer.Typer.retrieveSym(Typer.scala:3061)
        at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:3086)
        at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3197)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3275)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3279)
        at dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:3301)
        at dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:3347)
        at dotty.tools.dotc.typer.Typer.typedClassDef(Typer.scala:2789)
        at dotty.tools.dotc.typer.Typer.typedTypeOrClassDef$1(Typer.scala:3102)
        at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:3106)
        at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3197)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3275)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3279)
        at dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:3301)
        at dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:3347)
        at dotty.tools.dotc.typer.Typer.typedPackageDef(Typer.scala:2922)
        at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:3148)
        at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3198)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3275)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3279)
        at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:3391)
        at dotty.tools.dotc.typer.TyperPhase.typeCheck$$anonfun$1(TyperPhase.scala:47)
        at scala.runtime.function.JProcedure1.apply(JProcedure1.java:15)
        at scala.runtime.function.JProcedure1.apply(JProcedure1.java:10)
        at dotty.tools.dotc.core.Phases$Phase.monitor(Phases.scala:477)
        at dotty.tools.dotc.typer.TyperPhase.typeCheck(TyperPhase.scala:53)
        at dotty.tools.dotc.typer.TyperPhase.$anonfun$4(TyperPhase.scala:99)
        at scala.collection.Iterator$$anon$6.hasNext(Iterator.scala:479)
        at scala.collection.Iterator$$anon$9.hasNext(Iterator.scala:583)
        at scala.collection.immutable.List.prependedAll(List.scala:152)
        at scala.collection.immutable.List$.from(List.scala:684)
        at scala.collection.immutable.List$.from(List.scala:681)
        at scala.collection.IterableOps$WithFilter.map(Iterable.scala:898)
        at dotty.tools.dotc.typer.TyperPhase.runOn(TyperPhase.scala:100)
        at dotty.tools.dotc.Run.runPhases$1$$anonfun$1(Run.scala:315)
        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:1323)
        at dotty.tools.dotc.Run.runPhases$1(Run.scala:337)
        at dotty.tools.dotc.Run.compileUnits$$anonfun$1(Run.scala:348)
        at dotty.tools.dotc.Run.compileUnits$$anonfun$adapted$1(Run.scala:357)
        at dotty.tools.dotc.util.Stats$.maybeMonitored(Stats.scala:69)
        at dotty.tools.dotc.Run.compileUnits(Run.scala:357)
        at dotty.tools.dotc.Run.compileSources(Run.scala:261)
        at dotty.tools.dotc.Run.compile(Run.scala:246)
        at dotty.tools.dotc.Driver.doCompile(Driver.scala:37)
        at dotty.tools.dotc.Driver.process(Driver.scala:197)
        at dotty.tools.dotc.Driver.process(Driver.scala:165)
        at dotty.tools.dotc.Driver.process(Driver.scala:177)
        at dotty.tools.dotc.Driver.main(Driver.scala:207)
        at dotty.tools.dotc.Main.main(Main.scala)
Compilation failed
@WojciechMazur WojciechMazur added itype:bug area:typer itype:crash regression This worked in a previous version but doesn't anymore labels Jan 22, 2024
@WojciechMazur
Copy link
Contributor Author

Another project pjfanning/pekko-http-json (build logs) crash with similar stack trace, but differs exception couse:

Exception in thread "main" java.lang.AssertionError: assertion failed
        at scala.runtime.Scala3RunTime$.assertFailed(Scala3RunTime.scala:11)
        at dotty.tools.dotc.util.Spans$Span$.start$extension(Spans.scala:45)
        at dotty.tools.dotc.typer.Migrations.contextBoundParams(Migrations.scala:115)
        at dotty.tools.dotc.typer.Migrations.contextBoundParams$(Migrations.scala:28)
        at dotty.tools.dotc.typer.Typer.contextBoundParams(Typer.scala:120)

I'll try to provide a reproducer for this case as well

odersky added a commit to dotty-staging/dotty that referenced this issue Jan 22, 2024
Synthesized calls for default implicits needed a using clause when the
method was an implicit method, but had a context bound parameter in
3.4-migration.

Also, we can't rewrite adding a `using` clause if the argument list is
empty, since we are lacking precise position info.

Fixes scala#19506
@odersky
Copy link
Contributor

odersky commented Jan 22, 2024

I hope #19512 will fix both crashes

Kordyjan added a commit that referenced this issue Jan 23, 2024
…19512)

Synthesized calls for default implicits need a using clause when the
method is an implicit method with a context bound parameter, but only in
in 3.4-migration. Before this PR we still generated a normal empty
parameter list.

Also, we can't rewrite adding a `using` clause if the argument list is
empty, since we are lacking precise position info.

Fixes #19506
Kordyjan pushed a commit that referenced this issue Jan 23, 2024
Synthesized calls for default implicits needed a using clause when the
method was an implicit method, but had a context bound parameter in
3.4-migration.

Also, we can't rewrite adding a `using` clause if the argument list is
empty, since we are lacking precise position info.

Fixes #19506
Kordyjan pushed a commit that referenced this issue Jan 24, 2024
Synthesized calls for default implicits needed a using clause when the
method was an implicit method, but had a context bound parameter in
3.4-migration.

Also, we can't rewrite adding a `using` clause if the argument list is
empty, since we are lacking precise position info.

Fixes #19506
odersky added a commit to dotty-staging/dotty that referenced this issue Jan 27, 2024
Some classes get mapped to other classes at erasure. There's no need to transform
their info.

Fixes scala#19506
odersky added a commit to dotty-staging/dotty that referenced this issue Jan 27, 2024
WojciechMazur added a commit that referenced this issue Jun 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:typer 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.

2 participants