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

type inference fails with @remote annotation

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Not a Bug
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: Misc Compiler
    • Labels:
      None

      Description

      The code below

      import java.rmi.Remote
      import java.rmi.server.UnicastRemoteObject
      
      import scala.runtime.ObjectRef
      
      @remote
      trait RemoteObjectRef { // extends Remote {
        def elem: ObjectRef
      }
      
      class RemoteObjectRefImpl(x: ObjectRef)
      extends UnicastRemoteObject with RemoteObjectRef {
        def elem: ObjectRef = x
        override def toString() = x.toString()
      }
      
      object test extends Application {
      
        def bind(x: Remote): Remote = {
          println("RemoteRef.bind (Remote)"); x
        }
      
        def bind(x: RemoteObjectRef): RemoteObjectRef = {
          println("bind (RemoteObjectRef)"); x
        }
      
        bind(new RemoteObjectRefImpl(new ObjectRef()))
      }
      

      produces the following type error:

      test.scala:27: error: ambiguous reference to overloaded definition,
      both method bind in object test of type (RemoteObjectRef)RemoteObjectRef
      and  method bind in object test of type (java.rmi.Remote)java.rmi.Remote
      match argument types (RemoteObjectRefImpl)
        bind(new RemoteObjectRefImpl(new ObjectRef()))
        ^
      one error found
      

      but it compiles fine if you replace

      @remote
      trait RemoteObjectRef { def elem: ObjectRef }
      

      by

      trait RemoteObjectRef extends Remote { def elem: ObjectRef }
      

        Activity

        Hide
        Martin Odersky added a comment -

        That's completely as speced. @remote is not the same as `extends Remote' for the type checker.

        Show
        Martin Odersky added a comment - That's completely as speced. @remote is not the same as `extends Remote' for the type checker.
        Hide
        Martin Odersky added a comment -

        Milestone 2.6.1 deleted

        Show
        Martin Odersky added a comment - Milestone 2.6.1 deleted

          People

          • Assignee:
            Martin Odersky
            Reporter:
            Stephane Micheloud
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development