akka / akka

Build highly concurrent, distributed, and resilient message-driven applications on the JVM
https://akka.io
Other
12.99k stars 3.59k forks source link

improve compilation errors from ~> #18557

Open patriknw opened 8 years ago

patriknw commented 8 years ago

or provide a way to use more specific methods or type annotations to be able to get more specific error messages when in trouble

b.addEdge gives better error messages but it's a rather big syntax step to change from ~> to b.addEdge

Example of a mistake that I did:

val input = Source(List(1 -> "a", 2 -> "b", 3 -> "c"))
val output0: Sink[Int, _] = ???
val output1: Sink[String, _] = ???

  val partialGraph = FlowGraph.partial() { implicit b ⇒
  val unzip = b.add(Unzip[Int, String]())
  UniformFanOutShape(unzip.in, unzip.out0, unzip.out1)
}

val graph2 = FlowGraph.closed() { implicit b ⇒
  val partial = b.add(partialGraph)
  input ~> partial.in

  partial.out(0) ~> output0
  partial.out(1) ~> output1

  //b.addEdge(partial.out(0), b.add(output0).inlet)
  //b.addEdge(partial.out(1), b.add(output1).inlet)
}

The problem here was that I incorrectly used UniformFanOutShape, which resulted in Any as the type for the partial.out(0) and partial.out(1). The error message was:

overloaded method value ~> with alternatives: (to: akka.stream.SinkShape[Any])(implicit b: akka.stream.scaladsl.FlowGraph.Builder[_])Unit <and> (to: akka.stream.Graph[akka.stream.SinkShape[Any], _])(implicit b: akka.stream.scaladsl.FlowGraph.Builder[_])Unit <and> [Out](flow: akka.stream.FlowShape[Any,Out])(implicit b: akka.stream.scaladsl.FlowGraph.Builder[_])akka.stream.scaladsl.FlowGraph.Implicits.PortOps[Out,Unit] <and> [Out](junction: akka.stream.UniformFanOutShape[Any,Out])(implicit b: akka.stream.scaladsl.FlowGraph.Builder[_])akka.stream.scaladsl.FlowGraph.Implicits.PortOps[Out,Unit] <and> [Out](junction: akka.stream.UniformFanInShape[Any,Out])(implicit b: akka.stream.scaladsl.FlowGraph.Builder[_])akka.stream.scaladsl.FlowGraph.Implicits.PortOps[Out,Unit] <and> [Out](via: akka.stream.Graph[akka.stream.FlowShape[Any,Out],Any])(implicit b: akka.stream.scaladsl.FlowGraph.Builder[_])akka.stream.scaladsl.FlowGraph.Implicits.PortOps[Out,Unit] <and> (to: akka.stream.Inlet[Any])(implicit b: akka.stream.scaladsl.FlowGraph.Builder[_])Unit cannot be applied to (akka.stream.scaladsl.Sink[String,_$2])

overloaded method value ~> with alternatives: (to: akka.stream.SinkShape[Any])(implicit b: akka.stream.scaladsl.FlowGraph.Builder[_])Unit <and> (to: akka.stream.Graph[akka.stream.SinkShape[Any], _])(implicit b: akka.stream.scaladsl.FlowGraph.Builder[_])Unit <and> [Out](flow: akka.stream.FlowShape[Any,Out])(implicit b: akka.stream.scaladsl.FlowGraph.Builder[_])akka.stream.scaladsl.FlowGraph.Implicits.PortOps[Out,Unit] <and> [Out](junction: akka.stream.UniformFanOutShape[Any,Out])(implicit b: akka.stream.scaladsl.FlowGraph.Builder[_])akka.stream.scaladsl.FlowGraph.Implicits.PortOps[Out,Unit] <and> [Out](junction: akka.stream.UniformFanInShape[Any,Out])(implicit b: akka.stream.scala

When switching to addEdge it was clear:

type mismatch; found : akka.stream.Inlet[String] required: akka.stream.Inlet[Any]
rkuhn commented 8 years ago

One idea for an improvement is to add explicitly distinguished duplicates of the overloaded ~> methods such that it becomes clear what happens. These could be named sink_~> (for SinkShape), importSink_~> (for Graph[SinkShape, _]), etc.

patriknw commented 8 years ago

I like that, since when issues fixed it's easy to spot what to remove. Perhaps have a common prefix for all all those, so that those show up together in content assist (if that works with implicits)