Skip to content

MatchError Trees$TypeApply #9775

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
Sciss opened this issue Sep 11, 2020 · 1 comment · Fixed by #9827
Closed

MatchError Trees$TypeApply #9775

Sciss opened this issue Sep 11, 2020 · 1 comment · Fixed by #9827
Assignees
Milestone

Comments

@Sciss
Copy link
Contributor

Sciss commented Sep 11, 2020

Minimized code

trait ThreadedImpl {
  private val threadSync = new AnyRef
  @volatile private var wasClosed = false

  private val thread: Thread = ???

  final protected def isThreadRunning: Boolean =
    thread.isAlive && threadSync.synchronized(!wasClosed)
}

https://scastie.scala-lang.org/NO2TNVGaTtae15HdFyHW5Q

Output

crashes with

dotc: Error: TypeApply(Select(Apply(Select(Typed(This(Ident(ThreadedImpl)),TypeTree[TypeRef(ThisType(TypeRef(NoPrefix,module class impl)),trait ThreadedImpl)]),threadSync),List()),synchronized),List(TypeTree[TypeRef(ThisType(TypeRef(NoPrefix,module class scala)),class Boolean)])) (of class dotty.tools.dotc.ast.Trees$TypeApply)
scala.MatchError: TypeApply(Select(Apply(Select(Typed(This(Ident(ThreadedImpl)),TypeTree[TypeRef(ThisType(TypeRef(NoPrefix,module class impl)),trait ThreadedImpl)]),threadSync),List()),synchronized),List(TypeTree[TypeRef(ThisType(TypeRef(NoPrefix,module class scala)),class Boolean)])) (of class dotty.tools.dotc.ast.Trees$TypeApply)
	at dotty.tools.backend.jvm.BCodeBodyBuilder.lhs$lzyINIT1$1(BCodeBodyBuilder.scala:1310)
	at dotty.tools.backend.jvm.BCodeBodyBuilder.dotty$tools$backend$jvm$BCodeBodyBuilder$PlainBodyBuilder$$_$lhs$1(BCodeBodyBuilder.scala:1310)
	at dotty.tools.backend.jvm.BCodeBodyBuilder$PlainBodyBuilder.dotty$tools$backend$jvm$BCodeBodyBuilder$PlainBodyBuilder$$genCond(BCodeBodyBuilder.scala:1324)
	at dotty.tools.backend.jvm.BCodeBodyBuilder.dotty$tools$backend$jvm$BCodeBodyBuilder$PlainBodyBuilder$$_$genZandOrZor$1(BCodeBodyBuilder.scala:1321)
	at dotty.tools.backend.jvm.BCodeBodyBuilder$PlainBodyBuilder.dotty$tools$backend$jvm$BCodeBodyBuilder$PlainBodyBuilder$$genCond(BCodeBodyBuilder.scala:1326)
	at dotty.tools.backend.jvm.BCodeBodyBuilder$PlainBodyBuilder.genPrimitiveOp(BCodeBodyBuilder.scala:245)
	at dotty.tools.backend.jvm.BCodeBodyBuilder$PlainBodyBuilder.genApply(BCodeBodyBuilder.scala:774)
	at dotty.tools.backend.jvm.BCodeBodyBuilder$PlainBodyBuilder.genLoad(BCodeBodyBuilder.scala:356)
	at dotty.tools.backend.jvm.BCodeSkelBuilder$PlainSkelBuilder.emitNormalMethodBody$1(BCodeSkelBuilder.scala:708)
	at dotty.tools.backend.jvm.BCodeSkelBuilder$PlainSkelBuilder.genDefDef(BCodeSkelBuilder.scala:743)
	at dotty.tools.backend.jvm.BCodeSkelBuilder$PlainSkelBuilder.gen(BCodeSkelBuilder.scala:591)
	at dotty.tools.backend.jvm.BCodeSkelBuilder$PlainSkelBuilder.gen$$anonfun$1(BCodeSkelBuilder.scala:597)
	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.backend.jvm.BCodeSkelBuilder$PlainSkelBuilder.gen(BCodeSkelBuilder.scala:597)
	at dotty.tools.backend.jvm.BCodeSkelBuilder$PlainSkelBuilder.genPlainClass(BCodeSkelBuilder.scala:223)
	at dotty.tools.backend.jvm.GenBCodePipeline$Worker1.visit(GenBCode.scala:227)
	at dotty.tools.backend.jvm.GenBCodePipeline$Worker1.run(GenBCode.scala:192)
	at dotty.tools.backend.jvm.GenBCodePipeline.buildAndSendToDisk(GenBCode.scala:531)
	at dotty.tools.backend.jvm.GenBCodePipeline.run(GenBCode.scala:497)
	at dotty.tools.backend.jvm.GenBCode.run(GenBCode.scala:58)
	at dotty.tools.dotc.core.Phases$Phase.runOn$$anonfun$1(Phases.scala:296)
	at scala.collection.immutable.List.map(List.scala:250)
	at dotty.tools.dotc.core.Phases$Phase.runOn(Phases.scala:297)
	at dotty.tools.backend.jvm.GenBCode.runOn(GenBCode.scala:62)
	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.Main.process(Main.scala)
	at xsbt.CachedCompilerImpl.run(CachedCompilerImpl.java:69)

Expectation

should compile

@Sciss
Copy link
Contributor Author

Sciss commented Sep 11, 2020

this is a work around:

  final protected def isThreadRunning: Boolean =
    thread.isAlive && {
      val _wasClosed = threadSync.synchronized { wasClosed }
      !_wasClosed
    }

@smarter smarter self-assigned this Sep 11, 2020
smarter added a commit to dotty-staging/dotty that referenced this issue Sep 18, 2020
isPrimitive/getPrimitive are overloaded: they both have a version which
takes a symbol as input and a version which takes a tree, the latter can
handle array get and set primitives which map to different JVM
instructions depending on their type, but we don't care about that when
emitting conditions in genCond: we only need to look for primitives
which correspond to boolean operations and those are already handled by
the symbol versions of isPrimitive/getPrimitive. By using these methods
in genCond we avoid running some unnecessary code and we fix scala#9775 which
was triggered because the `getPrimitive` overload we were using required
forcing `lhs`. This change also aligns us with what the scalac backend
does.
nicolasstucki added a commit that referenced this issue Sep 22, 2020
Fix #9775: Fix primitive-in-condition handling in backend
@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.

3 participants