2

I have been chasing the following issue for quite a while and am hoping someone with more experience on this than myself can help me resolve it.

In my test-case the exact error is as follows:

java.lang.IllegalArgumentException: Could not find proxy for val user: specs.BasicSpec#User in List(value user, method applyOrElse, , method $anonfun$new$97, value fiveLetterNames, method $anonfun$new$90, method $anonfun$new$20, value , class BasicSpec, package specs, package ) (currentOwner= value fiveLetterNames )

The test can be found here:

https://github.com/outr/reactify/blob/master/shared/src/test/scala/specs/BasicSpec.scala#L227

This is the offending Macro:

https://github.com/outr/reactify/blob/master/shared/src/main/scala/com/outr/reactify/Macros.scala#L72

Without more information from the error I'm at a loss how to resolve this. Any assistance is greatly appreciated.

Pᴇʜ
  • 56,719
  • 10
  • 49
  • 73
darkfrog
  • 1,053
  • 8
  • 29

2 Answers2

2

I had the same problem in my project. The solution is not to use the same "lambda"* in macros more than one time.

"lambda" is the following:

def macroSample[A, B](c: blackbox.Context)
                     (lambda: c.Expr[A => B] /* <- lambda */) = { ... }

p.s. actually I cannot see your original code right now. That's a solution working in my case

Vitalii Honta
  • 297
  • 1
  • 10
0

To elaborate a bit on the above answer and my experience I ran into this issue using quill.

The basic code looked something like this

case class Foo(id: FooID, bar: String, value Int)
case class FooState(FooId: FooId, state: String, stateCount: Int)
case class FooCurrentState(FooId: FooId, state: String)
def alsoUpdate(f: FooState) = {
  Quote { 
    query[FooCurrentState].insert(
       ...
    ).onConflictUpdate(_.fooId)(...)
  }

def doInsert(foo: Foo, state: String, stateCount) = {
  val newFooState = 
  transaction {
    run {
        query[Foo].insert(lift(foo))
        query[FooState].insert(lift(newFooState))
        alsoUpdate(newFooState))
    }
  }
}

I got

java.lang.IllegalArgumentException: Could not find proxy for newFooState

Based on the accepted answer I refactored my code to be like this

case class Foo(id: FooID, bar: String, value Int)
case class FooState(FooId: FooId, state: String, stateCount: Int)
case class FooCurrentState(FooId: FooId, state: String)
def alsoUpdate(f: FooState) = {
  Quote { 
    query[FooCurrentState].insert(
       ...
    ).onConflictUpdate(_.fooId)(...)
  }

def doInsert(foo: Foo, state: String, stateCount) = {
  val newFooState = 
  transaction {
    run { query[Foo].insert(lift(foo)) }
    run { query[FooState].insert(lift(newFooState)) }
    run { alsoUpdate(newFooState)) }
    }
  }
}

Which did compile with out crashing the compiler.

haagmm
  • 583
  • 6
  • 10