Skip to content

assertion failed: no extension method found for #6989

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
thesamet opened this issue Aug 4, 2019 · 4 comments
Closed

assertion failed: no extension method found for #6989

thesamet opened this issue Aug 4, 2019 · 4 comments

Comments

@thesamet
Copy link

thesamet commented Aug 4, 2019

minimized code

package mypkg

object Container {
  class StringExtras(val s: String) extends AnyVal {
    def op(item: Int): Int = ???
  }
}

trait Container {
  import Container._
  implicit def mkStringExtras(s: String): StringExtras = new StringExtras(s)
}

In another file in src/test/scala directory:

package mypkg

class SimpleTest extends Container {
  "foo".op(5)
}

The problem goes away if I rename the trait from Container to anything else. It appears to be related to the trait and the companion object having the same name.

Stack trace
error] assertion failed: no extension method found for:
[error] 
[error]   method op:(item: Int): Int with signature Signature(List(scala.Int),scala.Int) in  <none>
[error] 
[error]  Candidates:
[error] 
[error]  
[error] 
[error]  Candidates (signatures normalized):
[error] 
[error]  
[error] 
[error]  Eligible Names: op$extension
[error] dotty.DottyPredef$.assertFail(DottyPredef.scala:16)
[error] dotty.tools.dotc.transform.ExtensionMethods$.extensionMethod$$anonfun$1(ExtensionMethods.scala:226)
[error] dotty.tools.dotc.core.Phases.atPhase$$anonfun$1(Phases.scala:35)
[error] dotty.tools.dotc.core.Periods.atPhase(Periods.scala:25)
[error] dotty.tools.dotc.core.Phases.atPhase(Phases.scala:35)
[error] dotty.tools.dotc.core.Contexts$Context.atPhase(Contexts.scala:71)
[error] dotty.tools.dotc.transform.ExtensionMethods$.extensionMethod(ExtensionMethods.scala:241)
[error] dotty.tools.dotc.transform.VCInlineMethods.rewire(VCInlineMethods.scala:68)
[error] dotty.tools.dotc.transform.VCInlineMethods.rewireIfNeeded(VCInlineMethods.scala:95)
[error] dotty.tools.dotc.transform.VCInlineMethods.transformApply(VCInlineMethods.scala:105)
[error] dotty.tools.dotc.transform.MegaPhase.goApply(MegaPhase.scala:611)
[error] dotty.tools.dotc.transform.MegaPhase.goApply(MegaPhase.scala:612)
[error] dotty.tools.dotc.transform.MegaPhase.transformUnnamed$1(MegaPhase.scala:272)
[error] dotty.tools.dotc.transform.MegaPhase.transformTree(MegaPhase.scala:396)
[error] dotty.tools.dotc.transform.MegaPhase.transformStat$2(MegaPhase.scala:406)
[error] dotty.tools.dotc.transform.MegaPhase.$anonfun$1(MegaPhase.scala:409)
[error] scala.collection.immutable.List.mapConserve(List.scala:179)
[error] dotty.tools.dotc.transform.MegaPhase.transformStats(MegaPhase.scala:409)
[error] dotty.tools.dotc.transform.MegaPhase.transformUnnamed$1(MegaPhase.scala:339)
[error] dotty.tools.dotc.transform.MegaPhase.transformTree(MegaPhase.scala:396)
[error] dotty.tools.dotc.transform.MegaPhase.transformNamed$1(MegaPhase.scala:251)
[error] dotty.tools.dotc.transform.MegaPhase.transformTree(MegaPhase.scala:394)
[error] dotty.tools.dotc.transform.MegaPhase.transformStat$2(MegaPhase.scala:404)
[error] dotty.tools.dotc.transform.MegaPhase.$anonfun$1(MegaPhase.scala:409)
[error] scala.collection.immutable.List.mapConserve(List.scala:179)
[error] dotty.tools.dotc.transform.MegaPhase.transformStats(MegaPhase.scala:409)
[error] dotty.tools.dotc.transform.MegaPhase.mapPackage$1(MegaPhase.scala:356)
[error] dotty.tools.dotc.transform.MegaPhase.transformUnnamed$1(MegaPhase.scala:359)
[error] dotty.tools.dotc.transform.MegaPhase.transformTree(MegaPhase.scala:396)
[error] dotty.tools.dotc.transform.MegaPhase.transformUnit(MegaPhase.scala:415)
[error] dotty.tools.dotc.transform.MegaPhase.run(MegaPhase.scala:427)
[error] dotty.tools.dotc.core.Phases$Phase.runOn$$anonfun$1(Phases.scala:316)
[error] scala.collection.immutable.List.map(List.scala:286)
[error] dotty.tools.dotc.core.Phases$Phase.runOn(Phases.scala:318)
[error] dotty.tools.dotc.Run.runPhases$4$$anonfun$4(Run.scala:158)
[error] dotty.runtime.function.JProcedure1.apply(JProcedure1.java:15)
[error] dotty.runtime.function.JProcedure1.apply(JProcedure1.java:10)
[error] scala.collection.IndexedSeqOptimized.foreach(IndexedSeqOptimized.scala:36)
@bishabosha
Copy link
Member

I can't reproduce this using the code you provided here, tried all releases from 0.15.0-RC1 onwards

@thesamet
Copy link
Author

thesamet commented Aug 15, 2019

Thanks for looking into it. I was unable to reproduce this today on the minimized code (I must have minimized too much before posting), but I can still reproduce this compiler crash with the original code. I will post an updated code example in the next few days.

@thesamet
Copy link
Author

@bishabosha I updated the example. The second file needs to be under src/test/scala, rather than in src/main/scala. For my own sanity, I put a minimal github repo and a travis build log that reproduces this:

https://github.com/thesamet/dotty-issue6989 - Clone and reproduce with sbt test

Travis log: https://travis-ci.org/thesamet/dotty-issue6989/builds/572359692

@bishabosha
Copy link
Member

Yes I can definitely reproduce this example now, thank you for updating.

odersky added a commit to dotty-staging/dotty that referenced this issue Aug 26, 2019
…ckling

scalacLinkedClass uses unforcedDecls which might miss a companion object when
unpickling. I tried to make scalacLinekdClass stricter, but ran into
problems. It turns out that it is finely balanced as it is.

The fix is to make sure the owner is completed before calling scalacLinkedClass
from an unpickler.
bishabosha added a commit that referenced this issue Aug 27, 2019
Fix #6989: Make sure scalacLinkedClass finds companion when unpickling
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

2 participants