Skip to content

Unable to use a given instance from a worksheet #7463

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
julienrf opened this issue Oct 28, 2019 · 3 comments
Closed

Unable to use a given instance from a worksheet #7463

julienrf opened this issue Oct 28, 2019 · 3 comments

Comments

@julienrf
Copy link
Contributor

julienrf commented Oct 28, 2019

minimized code

def sort[A](as: List[A])(given o: Ordering[A]): List[A] = {
  def insert(list: List[A], elem: A): List[A] =
    list match {
      case Nil          => elem :: Nil
      case head :: tail =>
        if o.lt(elem, head) then elem :: head :: tail
        else head :: insert(tail, elem)
    }
  as.foldLeft(Nil)(insert)
}

case class Rational(num: Int, denom: Int)

given Ordering[Rational] {
  def compare(x: Rational, y: Rational): Int =
    x.num * y.denom - x.denom * y.num
}

sort(List(Rational(1, 2), Rational(1, 3))) // java.lang.VerifyError: Bad operand type when invoking <init>

expectation

The compiled code should not throw a run-time exception.

Note that calling the sorted method on List does not produce the problem, and the same code pasted in a REPL does not produce the problem either.

@julienrf julienrf changed the title Unable to define given instance from a worksheet Unable to use a given instance from a worksheet Oct 28, 2019
@smarter
Copy link
Member

smarter commented Oct 28, 2019

Hopefully same root cause as #7424

@julienrf
Copy link
Contributor Author

Here is the full stack trace, in case that helps:

Exception Details:
  Location:
    rs$line$5$given_Ordering_Rational$.<init>()V @9: invokespecial
  Reason:
    Invalid type: 'rs$line$5$given_Ordering_Rational$' (current frame, stack[0])
  Current Frame:
    bci: @9
    flags: { }
    locals: { 'rs$line$5$given_Ordering_Rational$' }
    stack: { 'rs$line$5$given_Ordering_Rational$' }
  Bytecode:
    0x0000000: 2ab7 001e 2ab3 0020 2ab7 0021 2ab7 0022
    0x0000010: b1                                     

    at rs$line$6$.<init>(rs$line$6:1)
    at rs$line$6$.<clinit>(rs$line$6)
    at rs$line$6.res2(rs$line$6)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at dotty.tools.repl.Rendering.$anonfun$3(Rendering.scala:72)
    at scala.Option.map(Option.scala:242)
    at dotty.tools.repl.Rendering.valueOf(Rendering.scala:72)
    at dotty.tools.repl.Rendering.renderVal(Rendering.scala:95)
    at dotty.tools.repl.ReplDriver.displayMembers$3$$anonfun$3(ReplDriver.scala:285)
    at scala.collection.immutable.List.map(List.scala:219)
    at scala.collection.immutable.List.map(List.scala:79)
    at dotty.tools.repl.ReplDriver.displayMembers$6(ReplDriver.scala:285)
    at dotty.tools.repl.ReplDriver.displayDefinitions$$anonfun$3$$anonfun$2(ReplDriver.scala:311)
    at scala.Option.map(Option.scala:242)
    at dotty.tools.repl.ReplDriver.displayDefinitions$$anonfun$1(ReplDriver.scala:311)
    at dotty.tools.dotc.core.Phases.atPhase$$anonfun$1(Phases.scala:35)
    at dotty.tools.dotc.core.Periods.atPhase(Periods.scala:25)
    at dotty.tools.dotc.core.Phases.atPhase(Phases.scala:35)
    at dotty.tools.dotc.core.Contexts$Context.atPhase(Contexts.scala:71)
    at dotty.tools.repl.ReplDriver.displayDefinitions(ReplDriver.scala:317)
    at dotty.tools.repl.ReplDriver.compile$$anonfun$2(ReplDriver.scala:241)
    at scala.util.Either.fold(Either.scala:189)
    at dotty.tools.repl.ReplDriver.compile(ReplDriver.scala:241)
    at dotty.tools.repl.ReplDriver.interpret(ReplDriver.scala:193)
    at dotty.tools.repl.ReplDriver.run$$anonfun$1(ReplDriver.scala:136)
    at dotty.tools.repl.ReplDriver.withRedirectedOutput(ReplDriver.scala:148)
    at dotty.tools.repl.ReplDriver.run(ReplDriver.scala:137)
    at dotty.tools.languageserver.worksheet.ReplProcess$.main(ReplProcess.scala:13)
    at dotty.tools.languageserver.worksheet.ReplProcess.main(ReplProcess.scala)

@liufengyun
Copy link
Contributor

It works now.

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

3 participants