Scala Programming Language
  1. Scala Programming Language
  2. SI-5378

Structural types do not inspect bounds; unsoundness results

    Details

      Description

      Ring the big bell.

      
      class Coll[+T] {
        def contains = new { def apply[T1 <: T](value: T1) = ??? }
      }
      
      object Test {
        def main(args: Array[String]): Unit = {
          val xs = new Coll[List[String]]
          val ys: Coll[Traversable[String]] = xs
          
          println(ys contains Nil)
          // java.lang.NoSuchMethodException: Coll$$anon$1.apply(scala.collection.Traversable)
          //  at java.lang.Class.getMethod(Class.java:1605)
          //  at Test$.reflMethod$Method1(a.scala:14)
          //  at Test$.main(a.scala:14)
          //  at Test.main(a.scala)
        }
      }
      

      It should fail the way this does:

      def contains = new { def apply(value: T) = ??? } 
      
      ./a.scala:2: error: Parameter type in structural refinement may not refer to an abstract type defined outside that refinement
        def contains = new { def apply(value: T) = ??? } 
                                 ^
      one error found
      

        Issue Links

          Activity

          Hide
          Paul Phillips added a comment -

          You really want this one? It'll take me five minutes to fix it, I was just letting it age under scala reviewer for a minute.

          Show
          Paul Phillips added a comment - You really want this one? It'll take me five minutes to fix it, I was just letting it age under scala reviewer for a minute.
          Hide
          Adriaan Moors added a comment -

          please, have at it!

          Show
          Adriaan Moors added a comment - please, have at it!
          Hide
          Philipp Haller added a comment -

          Added test in 71c17a649e.

          Show
          Philipp Haller added a comment - Added test in 71c17a649e .
          Hide
          Paul Phillips added a comment -

          Patch pending.

          Show
          Paul Phillips added a comment - Patch pending.
          Hide
          Adriaan Moors added a comment -

          TODO: backport 31f073c0eb to 2.10.x

          Show
          Adriaan Moors added a comment - TODO: backport 31f073c0eb to 2.10.x
          Show
          Adriaan Moors added a comment - - edited 2.11: https://github.com/scala/scala/pull/1873 2.10.1: https://github.com/scala/scala/pull/2000
          Hide
          Paul Phillips added a comment -

          110b54a575278

          Show
          Paul Phillips added a comment - 110b54a575278

            People

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

              Dates

              • Created:
                Updated:
                Resolved:

                Development