https://kotlinlang.org logo
#arrow-meta
Title
# arrow-meta
m

mattmoore

05/24/2020, 9:04 PM
I'm tinkering with tests in Meta. It looks like
data class
is not supported for source code? If I have a test like this:
Copy code
@Test
  fun `destructuring example`() {
    assertThis(CompilerTest(
      config = {
        metaDependencies
      },
      code = {
        """|data class Person(val firstName: String, val lastName: String, val age: Int)
           |
           |val person = Person("Matt", "Moore", 100)
           |val (firstName, lastName, age) = person
           |""".source
      },
      assert = {
        allOf(
          "firstName".source.evalsTo("Matt"),
          "lastName".source.evalsTo("Moore"),
          "age".source.evalsTo(100)
        )
      }
    ))
  }
The code snippet fails to compile. Removing the
data
keyword succeeds, but then there are no
componentN
functions generated for destructuring.
Ran the test individually and seeing this:
Copy code
e: /var/folders/d4/jb8hn0bj4g3f1kgvrf5p19tw0000gn/T/Kotlin-Compilation4522202210550990282/sources/Source.kt: (31, 5): Destructuring declarations are only allowed for local variables/values
I also found other examples where
data class
is used. So I must be doing something wrong here. I'll keep looking.
Nevermind. It's a case of standard Kotlin here. You can't destructure at the top level. This is just following the same rules.
r

raulraja

05/25/2020, 11:45 AM
This is a bug most likely, try disabling the lens plugin if it’s still active in the etaPlugin, it may be interfering
also the identity template of data class may be wrong and it’s not considering all ellements
we had to add a hack at some point in meta to print the data modifier
leave just your plugin and the proofs plugin in MetaPlugin
also you can check in those other plugins uncommented as the lens plugins is unfinished and the comprehension one and others may not be necessary after all
m

mattmoore

05/25/2020, 5:02 PM
Removing lens plugin worked. I was also able to get it to work with lens enabled by adding optics dependency:
Copy code
config = { metaDependencies + addDependencies(arrowOptics) }