title: Kotlin: enums with associated values; function inside 'enum entry' gets `unresolved reference` error
body: <p>I need to create a list of events with a string as name and a list of pairs as properties, some events properties are the static value, some need dynamically changed, so I create specific functions inside the <code>enum entry</code> to update it but complied with error <code>unresolved reference</code>:</p>
  
  <p>Actually, what I want to implement is a list of enums with associated values, 
  something like these articles mentioned:</p>
  
  <ul>
  <li><a href="https://youtrack.jetbrains.com/issue/KT-4075" rel="nofollow noreferrer">KT-4075 Allow setters overloading for properties</a>, or</li>
  <li><a href="https://stackoverflow.com/questions/46153567/kotlin-single-property-with-multiple-setters-of-different-types">Kotlin: single property with multiple setters of different types</a>, or</li>
  <li><a href="https://medium.com/@da_pacheco/using-kotlins-sealed-class-to-approximate-swift-s-enum-with-associated-data-7e0abac88bbf" rel="nofollow noreferrer">Using Kotlin’s sealed class to approximate Swift’s enum with associated data</a></li>
  </ul>
  
  <p>Because I have more than 100 events, 95% of them are static, only several of them need to be updated during runtime, so sealed class might not suit my situation:</p>
  
  <pre><code>    enum class Event(val eventName: String, vararg eventProperties: Pair&lt;String, String?&gt;) {
          LOGIN_CLICKED("Login", ("View" to "button clicked")),
  
          LOGIN_SUCCEED("Login", ("Type" to "succeed")),
  
          LOGIN_ERROR("Login") {
              fun errorMessage(errorMessage: String) {
                  eventProperties = listOf("ErrorType" to errorMessage)
              }
          },
  
          // ... some other events
  
          LIST_ITEM_CLICKED("LIST") {
              fun listItemName(itemName: String) {
                  eventProperties = listOf("View" to itemName)
              }
          };
  
          var eventProperties: List&lt;Pair&lt;String, String?&gt;&gt;? = listOf(*eventProperties)
  
  
  // Although this approach can fix my problem, but I don't prefer it,
  // because these functions are only meaningful to specific enum item,
  // I don't want them be opened to all enum items.
  //
  //        fun errorMessage(errorMessage: String) {
  //            eventProperties = listOf("ErrorType" to errorMessage)
  //        }
  
  //        fun listItemName(itemName: String) {
  //            eventProperties = listOf("View" to itemName)
  //        }
      }
  
      fun main(args: Array&lt;String&gt;) {
  
          // unresolved reference
          println(Event.LOGIN_ERROR.eventProperties)
          Event.LOGIN_ERROR.errorMessage("error password")
          println(Event.LOGIN_ERROR.eventProperties)
      }
  </code></pre>