Details

      Description

      The below code shows a compiler flaw in that the wildcard "_" as value for a bounded type parameter either breaks the boundry - as it result in Any - or doesnt (as id hoped it to be) evaluates to the boundy.

      class SomeClass(val intValue:Int)
      class MyClass[T <: SomeClass](val myValue:T) 
      
      def myMethod(i:MyClass[_]) {
         i.myValue.intValue/2      // << error i is of type Any
      }
      
      def myMethod(i:MyClass[_ <: SomeClass]) {
         i.myValue.intValue/2      // << works
      }
      

        Issue Links

          Activity

          Hide
          karlw added a comment -

          opps.. a comment correction, the line

          val a = i.myValue.intValue/2 // << error i is of type Any

          should be

          val a = i.myValue.intValue/2 // << error i.myValue is of type Any

          Show
          karlw added a comment - opps.. a comment correction, the line val a = i.myValue.intValue/2 // << error i is of type Any should be val a = i.myValue.intValue/2 // << error i.myValue is of type Any
          Hide
          Martin Odersky added a comment -

          This a consequence of the current type checking algorithm, where bounds
          are checked only after variables are instantiated. I believe this will change once we go to contraint-based type inference. Assigning low priority until then.

          Show
          Martin Odersky added a comment - This a consequence of the current type checking algorithm, where bounds are checked only after variables are instantiated. I believe this will change once we go to contraint-based type inference. Assigning low priority until then.
          Hide
          A. P. Marki added a comment -

          At 2.10.0-M2,

          error: value intValue is not a member of _$1

          At 2.9.1.final,

          error: value intValue is not a member of Any

          Show
          A. P. Marki added a comment - At 2.10.0-M2, error: value intValue is not a member of _$1 At 2.9.1.final, error: value intValue is not a member of Any
          Show
          Paul Phillips added a comment - https://github.com/scala/scala/pull/2518
          Hide
          Adriaan Moors added a comment - - edited

          This will need some rethinking, as it caused several regressions in the wild. Slick and ScalaFX (SI-8197) both don't compile.

          reopened by: https://github.com/scala/scala/pull/3509

          Show
          Adriaan Moors added a comment - - edited This will need some rethinking, as it caused several regressions in the wild. Slick and ScalaFX ( SI-8197 ) both don't compile. reopened by: https://github.com/scala/scala/pull/3509
          Hide
          Adriaan Moors added a comment -

          The core of a likely more robust fix is in SI-6169, but we're not generalizing it for now.

          Show
          Adriaan Moors added a comment - The core of a likely more robust fix is in SI-6169 , but we're not generalizing it for now.
          Hide
          Stephen Compall added a comment - - edited

          If reversion is going into 2.11, the news item that cites this issue for 2.11 should be removed. Or at least updated to point to SI-6169.

          Show
          Stephen Compall added a comment - - edited If reversion is going into 2.11, the news item that cites this issue for 2.11 should be removed. Or at least updated to point to SI-6169 .
          Show
          Adriaan Moors added a comment - thanks, https://github.com/scala/make-release-notes/commit/9a7e2ae791056a4790c79f27cd3f3c713f1b689d

            People

            • Assignee:
              Adriaan Moors
              Reporter:
              karlw
            • Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

              • Created:
                Updated:

                Development