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

applyDynamic is not used for a call to apply that is not explicit

    Details

      Description

      import language.dynamics
      
      object I {
         val x = new X(3)
      
         // Doesn't compile.  It should be a call to applyDynamic("apply")(9)
         val y = x(9)
      
         class X(i: Int) extends Dynamic {
            def applyDynamic(name: String)(in: Int): Int = i + in
         }
      }
      
      I.scala:7: error: I.X does not take parameters
         val y = x(9)
                  ^
      

      The above is unexpected because applyDynamic does get called for update. The following compiles fine:

      import language.dynamics
      
      object I {
         val x = new X(3)
         x(9) = 12
      
         class X(i: Int) extends Dynamic {
            def applyDynamic(name: String)(left: Int, right: Int): Int = 
               i + left + right
         }
      }
      

        Activity

        Hide
        Josh Suereth added a comment -

        This SIP proposal mentions nothing about "apply". I think perhaps we just need to make a decision here, but this may be "not a bug".

        Show
        Josh Suereth added a comment - This SIP proposal mentions nothing about "apply". I think perhaps we just need to make a decision here, but this may be "not a bug".
        Hide
        Mark Harrah added a comment -

        Section 6.6 of the spec describes how `x(9)` is translated to `x.apply(9)`, so I don't think the SIP needs to mention anything specifically about "apply" unless there will be an exception that dynamic doesn't kick in for "apply". An updated section 6.6 for this SIP or an explicit note in the SIP would of course make this clearer, but because of the handling of "update", I think it is reasonable to infer the SIP means to handle "apply" like everything else.

        Show
        Mark Harrah added a comment - Section 6.6 of the spec describes how `x(9)` is translated to `x.apply(9)`, so I don't think the SIP needs to mention anything specifically about "apply" unless there will be an exception that dynamic doesn't kick in for "apply". An updated section 6.6 for this SIP or an explicit note in the SIP would of course make this clearer, but because of the handling of "update", I think it is reasonable to infer the SIP means to handle "apply" like everything else.
        Hide
        Grzegorz Kossakowski added a comment -

        I believe Mark is right here.

        Show
        Grzegorz Kossakowski added a comment - I believe Mark is right here.
        Hide
        Josh Suereth added a comment -

        Yeah, Mark is right. We either explicitly disallow or fix. I already bumped to critical, do we need to bump to blocker?

        Show
        Josh Suereth added a comment - Yeah, Mark is right. We either explicitly disallow or fix. I already bumped to critical, do we need to bump to blocker?
        Hide
        Grzegorz Kossakowski added a comment -

        I think we just need to find somebody who can fix it. Unfortunately, type checker is not area of my expertise but let me look around for folks more knowledgeable than me.

        Show
        Grzegorz Kossakowski added a comment - I think we just need to find somebody who can fix it. Unfortunately, type checker is not area of my expertise but let me look around for folks more knowledgeable than me.
        Hide
        Grzegorz Kossakowski added a comment -

        Nada has a lot of experience with dynamic so she is probably the best fit. She said she will have a look at this ticket on Tuesday.

        Show
        Grzegorz Kossakowski added a comment - Nada has a lot of experience with dynamic so she is probably the best fit. She said she will have a look at this ticket on Tuesday.
        Hide
        Grzegorz Kossakowski added a comment -
        Show
        Grzegorz Kossakowski added a comment - Fixed by Nada here: https://github.com/scala/scala/pull/1321

          People

          • Assignee:
            Nada Amin
            Reporter:
            Mark Harrah
          • Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development