Skip to content

Does not work in inline functionsΒ #88

@tschuchortdev

Description

@tschuchortdev

It seems to me that record4s does not work correctly neither in inline nor transparent inline functions (the difference is important since they are inlined at different times iirc). Probably this is an issue with how the type checking of transparent functions works, so not strictly a bug in this library, but perhaps you can find a better workaround or escalate the issue to the Scala compiler. In any case, I hope that my report will at least serve as documentation for other users.

import com.github.tarao.record4s.%

%(name = "hello") + (bla = 123)

def foo() = {
  %(name = "hello") + (bla = 123)
}

inline def bar() = {
  %(name = "hello") + (bla = 123)
}

transparent inline def bob() = {
  %(name = "hello") + (bla = 123)
}

inline def foobar() = {
  (
    %(name = "hello").asInstanceOf[% { val name: String }]
      + (bla = 123)
  ).asInstanceOf[% { val name: String; val bla: Int }]
}

foobar()

Output:

val res0: com.github.tarao.record4s.%{val name: String; val bla: Int} = %(name = hello, bla = 123)

def foo(): com.github.tarao.record4s.%{val name: String; val bla: Int}

-- [E008] Not Found Error: -----------------------------------------------------
2 |  %(name = "hello") + (bla = 123)
  |  ^^^^^^^^^^^^^^^^^^^
  |value + is not a member of Any, but could be made available as an extension method.
  |
  |One of the following imports might make progress towards fixing the problem:
  |
  |  import math.Fractional.Implicits.infixFractionalOps
  |  import math.Integral.Implicits.infixIntegralOps
  |  import math.Numeric.Implicits.infixNumericOps
  |
1 error found

-- [E008] Not Found Error: -----------------------------------------------------
2 |  %(name = "hello") + (bla = 123)
  |  ^^^^^^^^^^^^^^^^^^^
  |value + is not a member of Any, but could be made available as an extension method.
  |
  |One of the following imports might make progress towards fixing the problem:
  |
  |  import math.Fractional.Implicits.infixFractionalOps
  |  import math.Integral.Implicits.infixIntegralOps
  |  import math.Numeric.Implicits.infixNumericOps
  |
1 error found

def foobar(): com.github.tarao.record4s.%{val name: String; val bla: Int}

val res1: com.github.tarao.record4s.%{val name: String; val bla: Int} = %(name = hello, bla = 123)

PS: Let me just say that this is an amazing library that doesn't have nearly as many stars as it deserves. It is not only surprisingly usable, but also serves as a good example of whitebox macro techniques πŸ‘

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions