Skip to content

scalac fails on structure type match #7505

Closed

Description

@scabug

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.

Activity

  1. scabug commented on May 22, 2013

    @scabug
    Author

    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:

  2. scabug commented on May 31, 2013

    @scabug
    Author
  3. scabug commented on May 31, 2013

    @scabug
    Author
  4. added this to the 2.10.2-RC1 milestone on Apr 7, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions