Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: Scala 2.10.1
    • Component/s: Pattern Matcher
    • Labels:
      None
    • Environment:

      Mac OS X 10.8.3

      $ java -version
      java version "1.7.0_21"
      Java(TM) SE Runtime Environment (build 1.7.0_21-b12)
      Java HotSpot(TM) 64-Bit Server VM (build 23.21-b01, mixed mode)

      Description

      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.

        Issue Links

          Activity

          Hide
          Jason Zaugg added a comment -
          Show
          Jason Zaugg added a comment - Fixed by SI-7214 / https://github.com/scala/scala/commit/acd74cae
          Hide
          Jason Zaugg added a comment -
          Show
          Jason Zaugg added a comment - Test case: https://github.com/scala/scala/pull/2616/files

            People

            • Assignee:
              Jason Zaugg
              Reporter:
              Dan Boitnott
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development