Compiler can't figure out which version of exec()

Eclipse is giving me the following error:

ambiguous reference to overloaded definition, both method exec in trait Execs of type (scenario: io.gatling.core.structure.ScenarioBuilder)io.gatling.core.structure.ChainBuilder and method exec in trait Execs of type (chains: Iterable[io.gatling.core.structure.ChainBuilder])io.gatling.core.structure.ChainBuilder match argument types (com.cigna.common.RestfulService)

Here is part of the definition of RestfulService:

`
object RestfulService {
implicit def toRequest[T <: StructureBuilder[T]]( x: RestfulService ) : T = x.apply
}
trait RestfulService {
protected var formParams: Map[String,Any] = Map()
protected def formParameter( key: String, value: Any ) = {
formParams += ( key → value )
this
}
protected var queryParams: Map[String,Any] = Map()
protected def queryParameter( key: String, value: Any ) = {
queryParams += ( key → value )
this
}
protected var requestHeaders: Map[String,String] = Map()
protected def header( key: String, value: String ) = {
requestHeaders += ( key → value )
this
}
def apply[T <: StructureBuilder[T]] : T
}

class RestfulGET(
description: String,
url: String
) extends RestfulService {

def apply =
http( description )
.get( url )
.header( HttpHeaderNames.Accept, HttpHeaderValues.ApplicationJson )
.headers( requestHeaders )
.queryParamMap( queryParams )

}
`

The point is to be able to write code like this:

`
val foo = exec( SomeService.get.withPreferences )

`

where that is a sub-class of RestfulService that adds the withPreferences convenience method which adds a particular query parameter.

But because I made the implicit apply method convert to a sub-type of StructureBuilder[T], both possible versions of exec() apply, so eclipse complains. Am I doing something wrong? Is there a way around this?

Why do you target StructureBuilder and not just ChainBuilder?
exec(ScenarioBuilder) is mostly intended for people aiming to chain raw Recorder outputs (ie ScenarioBuilders) which is definitively not your case.

Then, I don’t get how exec(ScenarioBuilder) would match?!

I had been up until 2am working on it, so my head wasn’t quite where it needed to be.

It shouldn’t have been StructureBuilder, it was supposed to be AbstractHttpRequestBuilder. But that gives me the same error. But when I use ChainBuilder as the type, it doesn’t complain. Curious, but I won’t complain!

I’d need your exact code to reproduce, but honestly, the error you pasted doesn’t make sense (I suspect you went with trials and errors and you got slightly different errors at some point):
ambiguous reference to overloaded definition, both method
exec(scenario: ScenarioBuilder)ChainBuilder and method
exec(chains: Iterable[ChainBuilder])ChainBuilder
match argument types (com.cigna.common.RestfulService)

It seems you ended up with RestfulService being BOTH a ScenarioBuilder AND an Iterable[ChainBuilder] ?! Looks wrong to me.