Skip to content

Inlined += on a private var leads to a crash #9306

Closed
@sir-wabbit

Description

@sir-wabbit

Minimized code

// AE-12995b348e2b68518ebd2dcd26d15218bde07911
object Baz {
  class Foo {
    private var v = 0
    inline def run = {
      v += { v = 1 }
      v
    }
  }
  val foo = new Foo
  foo.run
}

but somewhat surprisingly this compiles:

object Baz {
  class Foo {
    private[this] var v = 0 // or just private var ...
    inline def run = {
      v += 1
      v
    }
  }
  val foo = new Foo
  foo.run
}

Output (click arrow to expand)

-- [E008] Not Found Error: test.scala:5:8 --------------------------------------
5 |      v += { v = 1 }
  |      ^^^^
  |      value += is not a member of Int - did you mean Int.!=?
exception occurred while typechecking test.scala
exception occurred while compiling test.scala
java.lang.AssertionError: assertion failed: Select(TypedSplice(Select(This(Ident(Foo)),v)),+) while compiling test.scala
Exception in thread "main" java.lang.AssertionError: assertion failed: Select(TypedSplice(Select(This(Ident(Foo)),v)),+)
	at dotty.DottyPredef$.assertFail(DottyPredef.scala:17)
	at dotty.tools.dotc.typer.Inliner$InlineTyper.typedSelect(Inliner.scala:1198)
	at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:2357)
	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2446)
	at dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:124)
	at dotty.tools.dotc.typer.Typer.op$1(Typer.scala:2513)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2522)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2525)
	at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:2639)
	at dotty.tools.dotc.typer.ReTyper.typedFunPart(ReTyper.scala:72)
	at dotty.tools.dotc.typer.Applications.realApply$1(Applications.scala:864)
	at dotty.tools.dotc.typer.Applications.typedApply(Applications.scala:999)
	at dotty.tools.dotc.typer.Inliner$InlineTyper.typedApply(Inliner.scala:1244)
	at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:2387)
	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2447)
	at dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:124)
	at dotty.tools.dotc.typer.Typer.op$1(Typer.scala:2513)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2522)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2525)
	at dotty.tools.dotc.typer.Typer.typedAssign(Typer.scala:837)
	at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:2394)
	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2447)
	at dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:124)
	at dotty.tools.dotc.typer.Typer.op$1(Typer.scala:2513)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2522)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2525)
	at dotty.tools.dotc.typer.Applications.typedOpAssign$1(Applications.scala:981)
	at dotty.tools.dotc.typer.Applications.$anonfun$16$$anonfun$1(Applications.scala:990)
	at dotty.tools.dotc.typer.Typer.tryEither(Typer.scala:2647)
	at dotty.tools.dotc.typer.Applications.$anonfun$6(Applications.scala:994)
	at dotty.tools.dotc.typer.Typer.tryEither(Typer.scala:2650)
	at dotty.tools.dotc.typer.Applications.typedApply(Applications.scala:995)
	at dotty.tools.dotc.typer.Inliner$InlineTyper.typedApply(Inliner.scala:1244)
	at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:2387)
	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2447)
	at dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:124)
	at dotty.tools.dotc.typer.Typer.op$1(Typer.scala:2513)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2522)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2525)
	at dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:2573)
	at dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:2595)
	at dotty.tools.dotc.typer.Typer.typedBlockStats(Typer.scala:863)
	at dotty.tools.dotc.typer.Typer.typedBlock(Typer.scala:867)
	at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:2395)
	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2447)
	at dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:124)
	at dotty.tools.dotc.typer.Typer.op$1(Typer.scala:2513)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2522)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2525)
	at dotty.tools.dotc.typer.ReTyper.typedTyped(ReTyper.scala:60)
	at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:2392)
	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2447)
	at dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:124)
	at dotty.tools.dotc.typer.Typer.op$1(Typer.scala:2513)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2522)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2525)
	at dotty.tools.dotc.typer.Inliner.op$1(Inliner.scala:738)
	at dotty.tools.dotc.typer.Inliner.inlined(Inliner.scala:754)
	at dotty.tools.dotc.typer.Inliner$.inlineCall(Inliner.scala:127)
	at dotty.tools.dotc.typer.Typer.adaptNoArgsOther$4(Typer.scala:3188)
	at dotty.tools.dotc.typer.Typer.adaptNoArgs$1(Typer.scala:3295)
	at dotty.tools.dotc.typer.Typer.adapt1(Typer.scala:3526)
	at dotty.tools.dotc.typer.Typer.op$3(Typer.scala:2850)
	at dotty.tools.dotc.typer.Typer.adapt(Typer.scala:2851)
	at dotty.tools.dotc.typer.Typer.op$1(Typer.scala:2513)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2522)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2525)
	at dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:2573)
	at dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:2595)
	at dotty.tools.dotc.typer.Typer.typedClassDef(Typer.scala:2045)
	at dotty.tools.dotc.typer.Typer.typedTypeOrClassDef$2(Typer.scala:2375)
	at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:2379)
	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2446)
	at dotty.tools.dotc.typer.Typer.op$1(Typer.scala:2513)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2522)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2525)
	at dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:2547)
	at dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:2595)
	at dotty.tools.dotc.typer.Typer.typedPackageDef(Typer.scala:2171)
	at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:2419)
	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2447)
	at dotty.tools.dotc.typer.Typer.op$1(Typer.scala:2513)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2522)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2525)
	at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:2639)
	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:42)
	at dotty.tools.dotc.typer.FrontEnd.typeCheck(FrontEnd.scala:85)
	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:333)
	at dotty.tools.dotc.typer.FrontEnd.runOn(FrontEnd.scala:114)
	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:194)
	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:202)
	at dotty.tools.dotc.Main.main(Main.scala)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions