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

Using this as default argument to constructor does not refer to enclosing object

    Details

      Description

      In the following code, the default argument to Bar is object Bar instead of object Main.

      However, scalac requires that both Main and Bar conform to the parameter type.

      I'd expect Main.this to be in scope, even though the expression is evaluated by Bar$.

      Reproduce Code

      package trythis
       
      //object Main { // type mismatch
      object Main extends Function0[Int] {
       
        class Bar(x: Function0[Int] = this) {
          override def toString = "X "+ x.toString +"="+ x()
        }
        object Bar extends Function0[Int] {
          def apply() = 21
          override def toString = "My Bar module"
        }
        def main(args: Array[String]): Unit = {
          println(new Bar())
        }
        override def toString = "My Main"
        def apply() = 17
      }
      

      Expected result

      X My Main=17
      

      Actual Result

      X My Bar module=21
      

        Attachments

          Activity

          Hide
          moors Adriaan Moors added a comment -

          I want to focus on the next puzzler, so didn't look to closely at the rest of the ticket.

          Show
          moors Adriaan Moors added a comment - I want to focus on the next puzzler, so didn't look to closely at the rest of the ticket.
          Hide
          apm A. P. Marki added a comment -

          Since this was my first ever contribution, and since I have to pick up my daughter to see the Met rebroadcast of La donna del lago so my day isn't a total bust, I'll go with my initial assessment. Not that I knew anything back then,

          Show
          apm A. P. Marki added a comment - Since this was my first ever contribution, and since I have to pick up my daughter to see the Met rebroadcast of La donna del lago so my day isn't a total bust, I'll go with my initial assessment. Not that I knew anything back then,
          Hide
          apm A. P. Marki added a comment -

          P.S. Damn you, Scala Puzzlers! Damn you to perdition's flame!

          Show
          apm A. P. Marki added a comment - P.S. Damn you, Scala Puzzlers! Damn you to perdition's flame!
          Hide
          apm A. P. Marki added a comment -

          The comment on the puzzler was that this is another issue.

          In the U.S., you get three years to amend a tax return and three years to amend a community contribution.

          But if you're lucky, it won't get fixed before the second edition of the puzzlers book.
          

          However, that should have read:

          You're lucky if Jason doesn't notice the issue, assign it to himself and fix it before Scala Days. 
          Or rather, at Scala Days during lunch the day of your presentation. Or maybe during the five
          minutes you give people to figure out what's going on.
          

          Show
          apm A. P. Marki added a comment - The comment on the puzzler was that this is another issue . In the U.S., you get three years to amend a tax return and three years to amend a community contribution. But if you're lucky, it won't get fixed before the second edition of the puzzlers book. However, that should have read: You're lucky if Jason doesn't notice the issue, assign it to himself and fix it before Scala Days. Or rather, at Scala Days during lunch the day of your presentation. Or maybe during the five minutes you give people to figure out what's going on.
          Hide
          apm A. P. Marki added a comment -

          Reclosing because the Puzzlers at ScalaDays should not result in an orgy of second-guessing. "Feel free to open a new ticket." What is the prize for being lucky 10000? Are we confident that Jira doesn't overflow?

          Show
          apm A. P. Marki added a comment - Reclosing because the Puzzlers at ScalaDays should not result in an orgy of second-guessing. "Feel free to open a new ticket." What is the prize for being lucky 10000? Are we confident that Jira doesn't overflow?

            People

            • Assignee:
              apm A. P. Marki
              Reporter:
              apm A. P. Marki
            • Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: