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

              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: