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

scalac fails on structure type match #7505

Closed
scabug opened this issue May 22, 2013 · 3 comments
Closed

scalac fails on structure type match #7505

scabug opened this issue May 22, 2013 · 3 comments
Assignees
Labels
Milestone

Comments

@scabug
Copy link

scabug commented May 22, 2013

The following code fails to compile:

// ContextProperty.scala
package scalacbug

import scala.language.implicitConversions
import scala.language.reflectiveCalls
import scala.math.ScalaNumericAnyConversions

case class ContextProperty(value: Any, shell: Boolean = false) {
  type HasToInt = { def toInt:Int }

  override def toString: String = value.toString

  def toInt: Int = value match {
    case n: ScalaNumericAnyConversions => n.toInt // Call this out explicitly for efficiency.
    case n: HasToInt => n.toInt                   // Fall back on reflection to find a toInt
    case s: Any => s.toString.toInt               // Finally, try string conversion
  }
}

scalac gives the following error:

$ scalac ContextProperty.scala 
ContextProperty.scala:12: error: error during expansion of this match (this is a scalac bug).
The underlying error was: type mismatch;
 found   : Boolean(true)
 required: AnyRef
  def toInt: Int = value match {
                         ^
one error found

If I comment line 14:

    case n: ScalaNumericAnyConversions => n.toInt // Call this out explicitly for efficiency.
//  case n: HasToInt => n.toInt                   // Fall back on reflection to find a toInt
    case s: Any => s.toString.toInt               // Finally, try string conversion

The class compiles without error or warning.

@scabug
Copy link
Author

scabug commented May 22, 2013

Imported From: https://issues.scala-lang.org/browse/SI-7505?orig=1
Reporter: Dan Boitnott (dboitnot)
Affected Versions: 2.10.1
Other Milestones: 2.11.0-M3
Duplicates #7214
Attachments:

@scabug
Copy link
Author

scabug commented May 31, 2013

@retronym said:
Fixed by #7214 / scala/scala@acd74cae

@scabug
Copy link
Author

scabug commented May 31, 2013

@scabug scabug closed this as completed Jun 9, 2013
@scabug scabug added the patmat label Apr 7, 2017
@scabug scabug added this to the 2.10.2-RC1 milestone Apr 7, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants