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

updateDynamic is not used in some contexts

    Details

      Description

      I discovered strange behavior of updateDynamic. I trying to compile following code:

      import language.dynamics
      
      class DynamicTest extends Dynamic {
        def selectDynamic(name: String) = s"value of $name"
        def updateDynamic(name: String)(value: Any) {
          println(s"You have just updated property '$name' with value: $value")
        }
      }
      
      object MyApp extends App {
        def testing() {
          val test = new DynamicTest
          test.firstName = "John"
        }
        
        testing()
      }
      

      Which produces following compilation error:

      # scalac MyApp.scala
      MyApp.scala:13: error: reassignment to val
          test.firstName = "John"
                         ^
      
      one error found
      

      If I will remove selectDynamic method from the DynamicTest I will receive another error: "error: value selectDynamic is not a member of DynamicTest".

      If I will define MyApp class like this:

      object MyApp extends App {
        val test = new DynamicTest
      
        test.firstName = "John"
      }
      

      Then everything compiles without any errors.

      BTW, I'm facing the same errors in the REPL.

        Activity

        Show
        Paul Phillips added a comment - https://github.com/scala/scala/pull/1681
        Show
        Jason Zaugg added a comment - https://github.com/scala/scala/commit/edbcc64483ac0009eeeb58fe31e57a411da9e4c6

          People

          • Assignee:
            Paul Phillips
            Reporter:
            Oleg Ilyenko
          • Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development