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

by-name argument creates spurious type mismatch

    Details

      Description

      
      object A {
        def f0[T](x: T): T = x
        def f1[T](x: => T): T = x
        def f2[T](x: () => T): T = x()
      
        val x0 = f0(this.getClass)  // ok
        val x1 = f1(this.getClass)
        val x2 = f2(this.getClass)  // ok
      
        // a.scala:7: error: type mismatch;
        //  found   : Class[_ <: A.type]
        //  required: Class[?0(in value x1)] where type ?0(in value x1) <: A.type
        // Note: A.type >: ?0, but Java-defined class Class is invariant in type T.
        // You may wish to investigate a wildcard type such as `_ >: ?0`. (SLS 3.2.10)
        //   val x1 = f1(this.getClass)
        //                    ^
        // one error found
      }
      

        Issue Links

          Activity

          Hide
          Paul Phillips added a comment -

          I would look at something like

          def fn(arr1: Array[_ <: AnyRef], arr2: Array[_ <: AnyRef]) 
          

          And see if you can somehow exploit the absence of that check to assign between those arrays.

          Show
          Paul Phillips added a comment - I would look at something like def fn(arr1: Array[_ <: AnyRef], arr2: Array[_ <: AnyRef]) And see if you can somehow exploit the absence of that check to assign between those arrays.
          Hide
          Adriaan Moors added a comment -

          i don't know why this is, but I have a feeling I'd need to reread the TAPL chapter before making a call here
          hence, rescheduling

          Show
          Adriaan Moors added a comment - i don't know why this is, but I have a feeling I'd need to reread the TAPL chapter before making a call here hence, rescheduling
          Hide
          Jason Zaugg added a comment -

          Martin drew a blank when looking at the code and the commit that introduced it.

          Show
          Jason Zaugg added a comment - Martin drew a blank when looking at the code and the commit that introduced it.
          Show
          Adriaan Moors added a comment - https://github.com/scala/scala/pull/2537
          Hide
          Paul Phillips added a comment -

          01716c8

          Show
          Paul Phillips added a comment - 01716c8

            People

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

              Dates

              • Created:
                Updated:
                Resolved:

                Development