Skip to content
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

Value class method with varargs parameter: crash #6644

Closed
scabug opened this issue Nov 10, 2012 · 8 comments
Closed

Value class method with varargs parameter: crash #6644

scabug opened this issue Nov 10, 2012 · 8 comments

Comments

@scabug
Copy link

scabug commented Nov 10, 2012

Sorry not minimized. Is there a prize for the first RC2 crasher? I didn't want to miss out for modesty.

There was a different crash in my week-old trunk build. Does it still count?

package testable

case class Cell(s: String) {
  import scala.language.postfixOps
  import scala.util.Try
  def isNumber: Boolean = Try { s.toInt } map (_ => true) recover { case _ => false } get
}

object Matchable {
  case class MatchCase[A,B](a: ()=>A, b: ()=>B)
  class MatchAssoc[A](val a: ()=>A) extends AnyVal {
    @inline def -->[B](b: =>B): MatchCase[A,B] = MatchCase(a,() => b)
  }
  implicit def MatchAssoc[A,B](a: =>A) = new MatchAssoc(() => a)
  implicit class Testable(val c: Cell) extends AnyVal {
    def matching(cases: MatchCase[Boolean, Unit]*): Unit = {
      cases find (_.a()) map (_.b()) getOrElse (throw new MatchError(Matchable))
    }
  }
}

object Test extends App {
  val c = Cell("3")
  val d = Cell("I heart Scala")
  import Matchable._
  def f(c: Cell) = c.matching (
    (c.isNumber) --> (println(s"$c is a number")),
    ( true ) --> (println(s"$c is something else"))
  )
  f(c)
  f(d)
}
@scabug
Copy link
Author

scabug commented Nov 10, 2012

Imported From: https://issues.scala-lang.org/browse/SI-6644?orig=1
Reporter: @som-snytt
Affected Versions: 2.10.0-RC2
Other Milestones: 2.10.0

@scabug
Copy link
Author

scabug commented Nov 10, 2012

@adriaanm said:
looks like a value class issue

scala.reflect.internal.Types$TypeError: type mismatch;
 found   : Seq[$line4.$read.$iw.$iw.Matchable.MatchCase[Boolean,Unit]]
 required: $line4.$read.$iw.$iw.Matchable.MatchCase[Boolean,Unit]
	at scala.tools.nsc.typechecker.Contexts$Context.issueCommon(Contexts.scala:405)
	at scala.tools.nsc.typechecker.Contexts$Context.issue(Contexts.scala:409)
	at scala.tools.nsc.typechecker.ContextErrors$ErrorUtils$.issueTypeError(ContextErrors.scala:83)
	at scala.tools.nsc.typechecker.ContextErrors$ErrorUtils$.issueNormalTypeError(ContextErrors.scala:68)
	at scala.tools.nsc.typechecker.ContextErrors$TyperContextErrors$TyperErrorGen$.AdaptTypeError(ContextErrors.scala:174)
	at scala.tools.nsc.typechecker.Typers$Typer.fallBack$1(Typers.scala:1248)
	at scala.tools.nsc.typechecker.Typers$Typer.adapt(Typers.scala:1253)
	at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:5246)
	at scala.tools.nsc.interpreter.ReplGlobal$$anon$1$$anon$2.typed(ReplGlobal.scala:28)
	at scala.tools.nsc.typechecker.Typers$Typer$$anonfun$51.apply(Typers.scala:2845)
	at scala.tools.nsc.typechecker.Typers$Typer$$anonfun$51.apply(Typers.scala:2845)
	at scala.tools.nsc.typechecker.Typers$Typer.withCondConstrTyper(Typers.scala:500)
	at scala.tools.nsc.typechecker.Typers$Typer.typedArg(Typers.scala:2845)
	at scala.tools.nsc.typechecker.Typers$Typer.loop$1(Typers.scala:2872)
	at scala.tools.nsc.typechecker.Typers$Typer.typedArgs(Typers.scala:2878)
	at scala.tools.nsc.typechecker.Typers$Typer.handleMonomorphicCall$1(Typers.scala:3134)
	at scala.tools.nsc.typechecker.Typers$Typer.doTypedApply(Typers.scala:3178)
	at scala.tools.nsc.typechecker.Typers$Typer.normalTypedApply$1(Typers.scala:4427)
	at scala.tools.nsc.typechecker.Typers$Typer.typedApply$1(Typers.scala:4459)
	at scala.tools.nsc.typechecker.Typers$Typer.typed1(Typers.scala:5160)
	at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:5237)
	at scala.tools.nsc.interpreter.ReplGlobal$$anon$1$$anon$2.typed(ReplGlobal.scala:28)
	at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:5288)
	at scala.tools.nsc.typechecker.Typers$Typer.typedPos(Typers.scala:5293)
	at scala.tools.nsc.transform.ExtensionMethods$Extender$$anonfun$transform$2$$anonfun$apply$6.apply(ExtensionMethods.scala:223)

@scabug
Copy link
Author

scabug commented Nov 10, 2012

@adriaanm said (edited on Nov 10, 2012 1:55:17 AM UTC):
minimized:

class Testable(val c: String) extends AnyVal {
  def matching(cases: Boolean*): Unit = cases contains true
}

@scabug
Copy link
Author

scabug commented Nov 10, 2012

@adriaanm said:
it's likely related to the repeated argument

@scabug
Copy link
Author

scabug commented Nov 10, 2012

@som-snytt said:
Yes, and just to confirm, it's a pre-existing issue, so no RC2 prize.

@scabug
Copy link
Author

scabug commented Nov 10, 2012

@retronym said:
scala/scala#1608

@scabug
Copy link
Author

scabug commented May 31, 2016

Ian Hellstrom (hellstorm) said (edited on May 31, 2016 7:54:03 AM UTC):
Interestingly, by adding the @varargs annotation you can still crash the compiler. I just tried it on 2.10.4 and 2.11.7 with the minimal example provided by Adriaan. Without the annotation (as in the example), it's indeed fixed.

@NthPortal
Copy link

Did not crash with @varargs when I tested it in the 2.12.4 REPL

Welcome to Scala 2.12.4 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_161).
Type in expressions for evaluation. Or try :help.

scala> class Testable(val c: String) extends AnyVal {
     | @annotation.varargs def matching(cases: Boolean*): Unit = cases contains true
     | }
defined class Testable

scala>

@SethTisue SethTisue modified the milestones: 2.13.0-M4, 2.12.0 Mar 13, 2018
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

5 participants