Uploaded image for project: '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
      

        Attachments

          Issue Links

            Activity

            Hide
            extempore 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
            extempore 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
            moors Adriaan Moors added a comment -

            please, have at it!

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

            Added test in 71c17a649e.

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

            Patch pending.

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

            TODO: backport 31f073c0eb to 2.10.x

            Show
            moors Adriaan Moors added a comment - TODO: backport 31f073c0eb to 2.10.x
            Show
            moors 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
            extempore Paul Phillips added a comment -

            110b54a575278

            Show
            extempore Paul Phillips added a comment - 110b54a575278

              People

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

                Dates

                • Created:
                  Updated:
                  Resolved: