Uploaded image for project: 'Scala Programming Language'
  1. Scala Programming Language
  2. SI-5703

Strange error on overriding generic Java method with Array parameter

    Details

      Description

      Base.java

      public abstract class Base<Params> {
      	abstract void func(Params[] params);
      }
      

      Implementation.scala

      class Implementation extends Base[Object] {
          override def func(params: Array[Object]) {}
      }
      

      Compilation error

      error: class Implementation needs to be abstract, since method func in class Base of type (x$1: Array[Object with Object])Unit is not defined
      (Note that Array[Params with Object] does not match Array[Object]: their type parameters differ)
      class Implementation extends Base[Object] {

      error: method func overrides nothing
      override def func(params: Array[Object]) {}

      Writing

      func(params: Array[Object with Object])

      fixes problem, but how is Object with Object different from just Object?

        Attachments

          Issue Links

            Activity

            Hide
            moors Adriaan Moors added a comment -

            the problem is that during override checking the types RefinedType(List(Object), EmptyScope) and TypeRef(.., Object, Nil) are seen as different, the refined type arises from the fix for 4390 (when scala&java are compiled together), or from the original restriction wrt generic arrays (see sigToType, RestrictJavaArraysMap)

            I have a fix in the works for Object{} and Object being seen as different, but I feel like the Array[T] handling could be improved

            Show
            moors Adriaan Moors added a comment - the problem is that during override checking the types RefinedType(List(Object), EmptyScope) and TypeRef(.., Object, Nil) are seen as different, the refined type arises from the fix for 4390 (when scala&java are compiled together), or from the original restriction wrt generic arrays (see sigToType, RestrictJavaArraysMap) I have a fix in the works for Object{} and Object being seen as different, but I feel like the Array [T] handling could be improved
            Show
            moors Adriaan Moors added a comment - fixed by https://github.com/adriaanm/scala/commit/7a5aaa9e23a98d60343cc0c4411b3fc395faa3ab

              People

              • Assignee:
                moors Adriaan Moors
                Reporter:
                kriomant Mikhail Trishchenkov
              • Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: