Skip to content

Missing desugaring case for extension methods. #9529

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
nicolasstucki opened this issue Aug 11, 2020 · 0 comments
Closed

Missing desugaring case for extension methods. #9529

nicolasstucki opened this issue Aug 11, 2020 · 0 comments

Comments

@nicolasstucki
Copy link
Contributor

Minimized code

given AnyRef = { // should have been `given AnyRef {`
  extension (n: Int)
    def plus(m: Int): Int = n + m
}

Output (click arrow to expand)

scala.MatchError: ExtMethods(List(),List(List(ValDef(n,Ident(Int),EmptyTree))),List(DefDef(plus,List(),List(List(ValDef(m,Ident(Int),EmptyTree))),Ident(Int),InfixOp(Ident(n),Ident(+),Ident(m))))) (of class dotty.tools.dotc.ast.untpd$ExtMethods) while compiling Foo.scala
Exception in thread "main" scala.MatchError: ExtMethods(List(),List(List(ValDef(n,Ident(Int),EmptyTree))),List(DefDef(plus,List(),List(List(ValDef(m,Ident(Int),EmptyTree))),Ident(Int),InfixOp(Ident(n),Ident(+),Ident(m))))) (of class dotty.tools.dotc.ast.untpd$ExtMethods)
        at dotty.tools.dotc.ast.desugar$.apply(Desugar.scala:1717)
        at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:2468)
        at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2484)
        at dotty.tools.dotc.typer.Typer.op$1(Typer.scala:2553)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2554)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2557)
        at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:2671)
        at dotty.tools.dotc.typer.Typer.typedBlock(Typer.scala:871)
        at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:2431)
        at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2484)
        at dotty.tools.dotc.typer.Typer.op$1(Typer.scala:2553)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2554)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2557)
        at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:2671)
        at dotty.tools.dotc.typer.Typer.$anonfun$32(Typer.scala:1946)
        at dotty.tools.dotc.typer.PrepareInlineable$.dropInlineIfError(PrepareInlineable.scala:217)
        at dotty.tools.dotc.typer.Typer.typedDefDef(Typer.scala:1946)
        at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:2400)
        at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2483)
        at dotty.tools.dotc.typer.Typer.op$1(Typer.scala:2553)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2554)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2557)
        at dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:2579)
        at dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:2627)
        at dotty.tools.dotc.typer.Typer.typedClassDef(Typer.scala:2081)
        at dotty.tools.dotc.typer.Typer.typedTypeOrClassDef$2(Typer.scala:2411)
        at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:2415)
        at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2483)
        at dotty.tools.dotc.typer.Typer.op$1(Typer.scala:2553)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2554)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2557)
        at dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:2579)
        at dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:2627)
        at dotty.tools.dotc.typer.Typer.typedPackageDef(Typer.scala:2207)
        at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:2455)
        at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2484)
        at dotty.tools.dotc.typer.Typer.op$1(Typer.scala:2553)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2554)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2557)
        at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:2671)
        at dotty.tools.dotc.typer.FrontEnd.liftedTree1$1(FrontEnd.scala:79)
        at dotty.tools.dotc.typer.FrontEnd.typeCheck$$anonfun$1(FrontEnd.scala:84)
        at dotty.runtime.function.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:12)
        at dotty.tools.dotc.typer.FrontEnd.monitor(FrontEnd.scala:43)
        at dotty.tools.dotc.typer.FrontEnd.typeCheck(FrontEnd.scala:85)
        at dotty.tools.dotc.typer.FrontEnd.runOn$$anonfun$3(FrontEnd.scala:120)
        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:333)
        at dotty.tools.dotc.typer.FrontEnd.runOn(FrontEnd.scala:120)
        at dotty.tools.dotc.Run.runPhases$4$$anonfun$4(Run.scala:180)
        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:190)
        at dotty.tools.dotc.Run.compileUnits$$anonfun$1(Run.scala:198)
        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:205)
        at dotty.tools.dotc.Run.compileSources(Run.scala:142)
        at dotty.tools.dotc.Run.compile(Run.scala:124)
        at dotty.tools.dotc.Driver.doCompile(Driver.scala:38)
        at dotty.tools.dotc.Driver.process(Driver.scala:195)
        at dotty.tools.dotc.Driver.process(Driver.scala:164)
        at dotty.tools.dotc.Driver.process(Driver.scala:176)
        at dotty.tools.dotc.Driver.main(Driver.scala:203)
        at dotty.tools.dotc.Main.main(Main.scala)
@nicolasstucki nicolasstucki self-assigned this Aug 13, 2020
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Aug 13, 2020
Desugar the extension method into a block with a Unit expression.
Also set a missing position for the ExtMethods tree.
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Aug 13, 2020
Desugar the extension method into a block with a Unit expression.
Also set a missing position for the ExtMethods tree.
nicolasstucki added a commit that referenced this issue Aug 14, 2020
Fix #9529: Desugar ExtMethods in expression position
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant