Search code examples
scalaintellij-idearabbitmqshapeless

Scala Intellij - Op-Rabbit Syntax highlighting issue


I'm trying to use op-rabbit https://github.com/SpinGo/op-rabbit to connect my Scala App to RabbitMq. The example code https://github.com/SpinGo/op-rabbit/blob/master/demo/src/main/scala/demo/Main.scala works perfectly fine.

I want to work on it with the Intellij-idea. The IDE makes problems on the consume code:

channel(qos=3) {
  consume(demoQueue) {
    body(as[Data]) { data =>
      println(s"received ${data}")
      ack
    }
  }
}

I get an error on data => ... it says its a type mismatch

Type mismatch, expected: ::[Data, HNil] => op_rabbit.Handler, actual: Data => op_rabbit.Handler

I would be absolutly fine with annotating the data variable manually if this solves the problem i tried to annotated data as HList from shapeless.

channel(qos=3) {
  consume(demoQueue) {
    body(as[Data]) { data: HList =>
      println(s"received ${data}")
      ack
    }
  }
}

The IDE was happy with it... unlucky the compiler not really :D :( . Like this the code doesnt compile anymore.

Any idea?

Intellij and the Scala Plugin are updated to the newest version.


Solution

  • Well, it's better if IDE complains and not compiler does.

    Type of data is Data and not HList or Data :: HNil

    channel(qos=3) {
      consume(demoQueue) {
        body(as[Data]) { (data: Data) =>
          println(s"received ${data}")
          ack
        }
      }
    }
    

    You should get used that IDE highlights code in Scala sometimes incorrectly. Path-dependent types, implicits, macros etc. are sometimes too complicated for IDE to handle.


    The following code is highlighted correctly in 2017.3 EAP (Ultimate Edition) Build #IU-173.3302.5

    val directive = body(as[Data])
    
    channel(qos = 3)(
      consume(demoQueue)(
        directive(data => {
          println(s"received ${data}")
          ack
        })
      )
    )