bug
bug copied to clipboard
Errors in certain unapplications persevere through silent=true
import scala.language.experimental.macros
import scala.reflect.macros.TypecheckException
import scala.reflect.macros.whitebox.Context
object Macros {
def typecheck_impl(c: Context)(code: c.Expr[String]): c.Expr[Option[String]] = {
import c.universe._
val Expr(Literal(Constant(codeStr: String))) = code
try {
c.typecheck(c.parse(codeStr))
c.Expr(q"None: Option[String]")
} catch {
case e: TypecheckException =>
c.Expr(q"Some(${ e.toString }): Option[String]")
}
}
def typecheck(code: String): Option[String] = macro typecheck_impl
}
case class Foo(i: Int, c: Char)
object Bar {
def unapply(foo: Foo): Option[(Int, Char)] = Some((foo.i, foo.c))
}
object Test {
println(Macros.typecheck("val Foo(x, y, z) = Foo(1, 'a')"))
println(Macros.typecheck("val Bar(x, y, z) = Foo(1, 'a')"))
}
<macro>:1: error: too many patterns for object Bar offering (Int, Char): expected 2, found 3
val Bar(x, y, z) = Foo(1, 'a')
^
one error found
Imported From: https://issues.scala-lang.org/browse/SI-8719?orig=1 Reporter: @xeno-by Affected Versions: 2.11.0
@xeno-by said: Looks like the error in question is emitted by reporter.error as opposed to the standard mechanism of Context.issue(AbsTypeError): https://github.com/scala/scala/blob/75ac2250156dc36f072d44b82b5b82dc155691d8/src/compiler/scala/tools/nsc/transform/patmat/ScalacPatternExpanders.scala#L106
@xeno-by said: https://github.com/scala/scala/pull/3876