Skip to content

byname implicit depending on recursive given crash #8182

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

Closed
bishabosha opened this issue Feb 3, 2020 · 1 comment · Fixed by #11037
Closed

byname implicit depending on recursive given crash #8182

bishabosha opened this issue Feb 3, 2020 · 1 comment · Fixed by #11037

Comments

@bishabosha
Copy link
Member

bishabosha commented Feb 3, 2020

minimized code

package example

trait Show[-A]:
  extension (a: A) def show: String

given (using rec: Show[String]): Show[String] = ??? // must be Show[String] as the argument

given (using rec: => Show[String]): Show[Option[String]] = ??? // must be byname argument

def test = Option("").show

Crash output (click arrow to expand)

[info] running (fork) dotty.tools.dotc.Main -classpath /Users/jamie/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/org/scala-lang/scala-library/2.13.1/scala-library-2.13.1.jar:/Users/jamie/Workspace/dotty/library/../out/bootstrap/dotty-library-bootstrapped/scala-0.23/dotty-library_0.23-0.23.0-bin-SNAPSHOT.jar -d local local/Kernel.scala
exception occurred while typechecking local/Kernel.scala
exception occurred while compiling local/Kernel.scala
Exception in thread "main" java.lang.AssertionError: assertion failed: dotty.tools.dotc.typer.Applications$ExtMethodApply@4c3 while compiling local/Kernel.scala
java.lang.AssertionError: assertion failed: dotty.tools.dotc.typer.Applications$ExtMethodApply@4c3
        at dotty.DottyPredef$.assertFail(DottyPredef.scala:17)
        at dotty.tools.dotc.ast.Trees$Instance$TreeAccumulator.foldMoreCases(Trees.scala:1466)
        at dotty.tools.dotc.ast.Trees$Instance$TreeAccumulator.foldOver(Trees.scala:1461)
        at dotty.tools.dotc.ast.tpd$$anon$5.apply(tpd.scala:1041)
        at dotty.tools.dotc.ast.tpd$$anon$5.apply(tpd.scala:1041)
        at dotty.tools.dotc.ast.tpd$TreeOps$.existsSubTree$extension(tpd.scala:1043)
        at dotty.tools.dotc.typer.SearchRoot.$anonfun$10$$anonfun$2(Implicits.scala:1916)
        at scala.collection.immutable.List.exists(List.scala:367)
        at dotty.tools.dotc.typer.SearchRoot.$anonfun$11(Implicits.scala:1916)
        at scala.collection.StrictOptimizedIterableOps.$anonfun$partition$1(StrictOptimizedIterableOps.scala:34)
        at scala.collection.IterableOnceOps.foreach(IterableOnce.scala:553)
        at scala.collection.IterableOnceOps.foreach$(IterableOnce.scala:551)
        at scala.collection.AbstractIterator.foreach(Iterator.scala:1274)
        at scala.collection.StrictOptimizedIterableOps.partition(StrictOptimizedIterableOps.scala:34)
        at scala.collection.StrictOptimizedIterableOps.partition$(StrictOptimizedIterableOps.scala:32)
        at scala.collection.immutable.List.partition(List.scala:79)
        at dotty.tools.dotc.typer.SearchRoot.prune$1(Implicits.scala:1916)
        at dotty.tools.dotc.typer.SearchRoot.emitDictionary(Implicits.scala:1922)
        at dotty.tools.dotc.typer.Implicits.op$1(Implicits.scala:1363)
        at dotty.tools.dotc.typer.Implicits.inferImplicit(Implicits.scala:1364)
        at dotty.tools.dotc.typer.Typer.inferImplicit(Typer.scala:83)
        at dotty.tools.dotc.typer.Implicits.inferView(Implicits.scala:680)
        at dotty.tools.dotc.typer.Typer.inferView(Typer.scala:83)
        at dotty.tools.dotc.typer.Implicits.viewExists(Implicits.scala:655)
        at dotty.tools.dotc.typer.Typer.viewExists(Typer.scala:83)
        at dotty.tools.dotc.typer.ProtoTypes$Compatibility.isCompatible(ProtoTypes.scala:37)
        at dotty.tools.dotc.typer.Typer.isCompatible(Typer.scala:83)
        at dotty.tools.dotc.typer.ProtoTypes$Compatibility.constrainResult(ProtoTypes.scala:81)
        at dotty.tools.dotc.typer.Typer.constrainResult(Typer.scala:83)
        at dotty.tools.dotc.typer.ProtoTypes$Compatibility.constrainResult(ProtoTypes.scala:102)
        at dotty.tools.dotc.typer.Typer.constrainResult(Typer.scala:83)
        at dotty.tools.dotc.typer.Applications$Application.init(Applications.scala:345)
        at dotty.tools.dotc.typer.Applications$TypedApply.<init>(Applications.scala:690)
        at dotty.tools.dotc.typer.Applications$ApplyToUntyped.<init>(Applications.scala:792)
        at dotty.tools.dotc.typer.Applications.simpleApply$1(Applications.scala:866)
        at dotty.tools.dotc.typer.Applications.realApply$7$$anonfun$6(Applications.scala:927)
        at dotty.tools.dotc.typer.Typer.tryEither(Typer.scala:2375)
        at dotty.tools.dotc.typer.Applications.realApply$1(Applications.scala:938)
        at dotty.tools.dotc.typer.Applications.typedApply(Applications.scala:973)
        at dotty.tools.dotc.typer.Typer.typedApply(Typer.scala:83)
        at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:2151)
        at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2209)
        at dotty.tools.dotc.typer.Typer.op$1(Typer.scala:2247)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2256)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2259)
        at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:2367)
        at dotty.tools.dotc.typer.Typer.typeSelectOnTerm$1(Typer.scala:489)
        at dotty.tools.dotc.typer.Typer.typedSelect(Typer.scala:513)
        at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:2131)
        at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2208)
        at dotty.tools.dotc.typer.ProtoTypes$FunProto.$anonfun$2(ProtoTypes.scala:340)
        at dotty.tools.dotc.typer.ProtoTypes$FunProto.cacheTypedArg(ProtoTypes.scala:296)
        at dotty.tools.dotc.typer.ProtoTypes$FunProto.typedArg(ProtoTypes.scala:341)
        at dotty.tools.dotc.typer.Applications$ApplyToUntyped.typedArg(Applications.scala:793)
        at dotty.tools.dotc.typer.Applications$ApplyToUntyped.typedArg(Applications.scala:793)
        at dotty.tools.dotc.typer.Applications$Application.$anonfun$4$$anonfun$1(Applications.scala:590)
        at scala.collection.immutable.List.map(List.scala:219)
        at dotty.tools.dotc.typer.Applications$Application.$anonfun$2(Applications.scala:590)
        at dotty.tools.dotc.typer.Applications.harmonic(Applications.scala:1940)
        at dotty.tools.dotc.typer.Typer.harmonic(Typer.scala:83)
        at dotty.tools.dotc.typer.Applications$Application.matchArgs(Applications.scala:590)
        at dotty.tools.dotc.typer.Applications$Application.init(Applications.scala:354)
        at dotty.tools.dotc.typer.Applications$TypedApply.<init>(Applications.scala:690)
        at dotty.tools.dotc.typer.Applications$ApplyToUntyped.<init>(Applications.scala:792)
        at dotty.tools.dotc.typer.Applications.simpleApply$1(Applications.scala:866)
        at dotty.tools.dotc.typer.Applications.realApply$7$$anonfun$6(Applications.scala:927)
        at dotty.tools.dotc.typer.Typer.tryEither(Typer.scala:2375)
        at dotty.tools.dotc.typer.Applications.realApply$1(Applications.scala:938)
        at dotty.tools.dotc.typer.Applications.typedApply(Applications.scala:973)
        at dotty.tools.dotc.typer.Typer.typedApply(Typer.scala:83)
        at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:2151)
        at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2209)
        at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:2194)
        at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2209)
        at dotty.tools.dotc.typer.ProtoTypes$FunProto.$anonfun$2(ProtoTypes.scala:340)
        at dotty.tools.dotc.typer.ProtoTypes$FunProto.cacheTypedArg(ProtoTypes.scala:296)
        at dotty.tools.dotc.typer.ProtoTypes$FunProto.typedArg(ProtoTypes.scala:341)
        at dotty.tools.dotc.typer.Applications$ApplyToUntyped.typedArg(Applications.scala:793)
        at dotty.tools.dotc.typer.Applications$ApplyToUntyped.typedArg(Applications.scala:793)
        at dotty.tools.dotc.typer.Applications$Application.addTyped$1(Applications.scala:529)
        at dotty.tools.dotc.typer.Applications$Application.matchArgs(Applications.scala:598)
        at dotty.tools.dotc.typer.Applications$Application.init(Applications.scala:354)
        at dotty.tools.dotc.typer.Applications$TypedApply.<init>(Applications.scala:690)
        at dotty.tools.dotc.typer.Applications$ApplyToUntyped.<init>(Applications.scala:792)
        at dotty.tools.dotc.typer.Applications.simpleApply$1(Applications.scala:866)
        at dotty.tools.dotc.typer.Applications.realApply$7$$anonfun$6(Applications.scala:927)
        at dotty.tools.dotc.typer.Typer.tryEither(Typer.scala:2375)
        at dotty.tools.dotc.typer.Applications.realApply$1(Applications.scala:938)
        at dotty.tools.dotc.typer.Applications.typedApply(Applications.scala:973)
        at dotty.tools.dotc.typer.Typer.typedApply(Typer.scala:83)
        at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:2151)
        at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2209)
        at dotty.tools.dotc.typer.Typer.op$1(Typer.scala:2247)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2256)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2259)
        at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:2367)
        at dotty.tools.dotc.typer.Typer.typedDefDef(Typer.scala:1679)
        at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:2138)
        at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2208)
        at dotty.tools.dotc.typer.Typer.op$1(Typer.scala:2247)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2256)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2259)
        at dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:2281)
        at dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:2325)
        at dotty.tools.dotc.typer.Typer.typedClassDef(Typer.scala:1812)
        at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:2141)
        at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2208)
        at dotty.tools.dotc.typer.Typer.op$1(Typer.scala:2247)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2256)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2259)
        at dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:2281)
        at dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:2325)
        at dotty.tools.dotc.typer.Typer.typedPackageDef(Typer.scala:1938)
        at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:2182)
        at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2209)
        at dotty.tools.dotc.typer.Typer.op$1(Typer.scala:2247)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2256)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2259)
        at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:2367)
        at dotty.tools.dotc.typer.FrontEnd.liftedTree1$2(FrontEnd.scala:78)
        at dotty.tools.dotc.typer.FrontEnd.typeCheck$$anonfun$1(FrontEnd.scala:83)
        at dotty.runtime.function.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:12)
        at dotty.tools.dotc.typer.FrontEnd.monitor(FrontEnd.scala:42)
        at dotty.tools.dotc.typer.FrontEnd.typeCheck(FrontEnd.scala:84)
        at dotty.tools.dotc.typer.FrontEnd.runOn$$anonfun$3(FrontEnd.scala:114)
        at dotty.runtime.function.JProcedure1.apply(JProcedure1.java:15)
        at dotty.runtime.function.JProcedure1.apply(JProcedure1.java:10)
        at scala.collection.immutable.List.foreach(List.scala:305)
        at dotty.tools.dotc.typer.FrontEnd.runOn(FrontEnd.scala:114)
        at dotty.tools.dotc.Run.runPhases$4$$anonfun$4(Run.scala:167)
        at dotty.runtime.function.JProcedure1.apply(JProcedure1.java:15)
        at dotty.runtime.function.JProcedure1.apply(JProcedure1.java:10)
        at scala.collection.ArrayOps$.foreach$extension(ArrayOps.scala:1323)
        at dotty.tools.dotc.Run.runPhases$5(Run.scala:177)
        at dotty.tools.dotc.Run.compileUnits$$anonfun$1(Run.scala:185)
        at dotty.runtime.function.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:12)
        at dotty.tools.dotc.util.Stats$.maybeMonitored(Stats.scala:64)
        at dotty.tools.dotc.Run.compileUnits(Run.scala:192)
        at dotty.tools.dotc.Run.compileSources(Run.scala:129)
        at dotty.tools.dotc.Run.compile(Run.scala:112)
        at dotty.tools.dotc.Driver.doCompile(Driver.scala:36)
        at dotty.tools.dotc.Driver.process(Driver.scala:189)
        at dotty.tools.dotc.Driver.process(Driver.scala:158)
        at dotty.tools.dotc.Driver.process(Driver.scala:170)
        at dotty.tools.dotc.Driver.main(Driver.scala:197)
        at dotty.tools.dotc.Main.main(Main.scala)
@odersky
Copy link
Contributor

odersky commented Jan 7, 2021

This would be fixed if we could do extension methods without resorting to ExtMethodApply

@odersky odersky self-assigned this Jan 7, 2021
odersky added a commit to dotty-staging/dotty that referenced this issue Jan 8, 2021
Move some code out of `adapt` and `assignType`, to be re-used later in `typedSelect`.

The aim of the refactoring is to move all select-dependent adaptations and re-tries into
typedSelect. Right now some are in `adapt` and some are in `assignType`. This is awkward
since it means that

 - we do too much in `TypeAssigner`. Sine it aims to be minimal `TypeAssigner` should have no business doing adaptations
   and retries.
 - wo do some adaptations too early in `adpt`. This means we need the cludge of wrapping
   trees in `ExtMethodApply` which causes scala#8182, among others.
odersky added a commit to dotty-staging/dotty that referenced this issue Jan 8, 2021
Move some code out of `adapt` and `assignType`, to be re-used later in `typedSelect`.

The aim of the refactoring is to move all select-dependent adaptations and re-tries into
typedSelect. Right now some are in `adapt` and some are in `assignType`. This is awkward
since it means that

 - we do too much in `TypeAssigner`. Sine it aims to be minimal `TypeAssigner` should have no business doing adaptations
   and retries.
 - wo do some adaptations too early in `adpt`. This means we need the cludge of wrapping
   trees in `ExtMethodApply` which causes scala#8182, among others.
odersky added a commit to dotty-staging/dotty that referenced this issue Jan 11, 2021
The aim of the refactoring is to be clearer and to be able to drop ExtMethodApply.

Two main strategies:

 1. Move some code out of adapt and assignType into typedSelect.
 2. Concentrate extension method expansion and conversions for selections in a
    method `tryExtensionOrConversion. The method is called from `typedSelect`
    and `tryInsertImplicitOnQualifier`.

The aim of the refactoring is to move all select-dependent adaptations and re-tries into
typedSelect. Right now some are in adapt and some are in assignType. This is awkward
since it means that

 - we do too much in TypeAssigner. Sine it aims to be minimal TypeAssigner should have no business doing adaptations
and retries.
 - we do some adaptations too early in adpt. This means we need the kludge of wrapping
trees in ExtMethodApply which causes scala#8182, among others.

Fixes scala#8182
odersky added a commit to dotty-staging/dotty that referenced this issue Jan 15, 2021
The aim of the refactoring is to be clearer and to be able to drop ExtMethodApply.

Two main strategies:

  1. Move some code out of adapt and assignType into typedSelect.
  2. Concentrate extension method expansion and conversions for selections in a
    method `tryExtensionOrConversion. The method is called from `typedSelect`
    and `tryInsertImplicitOnQualifier`.

The aim of the refactoring is to move all select-dependent adaptations and re-tries into
typedSelect. Right now some are in adapt and some are in assignType. This is awkward
since it means that

  - we do too much in TypeAssigner. Sine it aims to be minimal TypeAssigner should have no business doing adaptations
and retries.
  - we do some adaptations too early in adpt. This means we need the kludge of wrapping
trees in ExtMethodApply which causes scala#8182, among others.

Fixes scala#8182
@Kordyjan Kordyjan added this to the 3.0.0 milestone Aug 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants