-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Description
Compiler version
Tested on latest LTS 3.3.5 and latest Next 3.6.4
Minimized code
Full scala-cli runnable reproduction: https://gist.github.com/majk-p/081f79021769b904cd8399a339bd6e94
Given following API definition
object api {
def expect[
CompanionObject,
EventType
](
eventTag: CompanionObject,
partitionKey: Option[String] = None
)(
condition: EventType => Boolean
)(using
withIsTest: EventType => { val isTest: Boolean },
streamArnFor: StreamArnFor[EventType],
): Option[EventType] = ???
}
When user attempts to compile api invocation without StreamArnFor
instance in given scope:
api.expect(MyEvent){ (event: MyEvent) => event.id.nonEmpty }
Output
The compiler responds with following error
[error] Found: A => A
[error] Required: MyEvent => Object{val isTest: Boolean}
[error] api.expect(MyEvent){ (event: MyEvent) => event.id.nonEmpty }
[error] ^
Expectation
I'd expect it to point user to the missing given instance:
[error] No given instance of type StreamArnFor[MyEvent] was found
[error] api.expect(MyEvent){ (event: MyEvent) => event.id.nonEmpty }
[error] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Workaround 1
Full runnable workaround: https://gist.github.com/majk-p/06639b0d98f0bb88b60b1ba3355a95ff
Changing the order of using
clauses such that the StreamArnFor
is first makes the compiler report the correct error.
object api {
def expect[
CompanionObject,
EventType
](
eventTag: CompanionObject,
partitionKey: Option[String] = None
)(
condition: EventType => Boolean
)(using
streamArnFor: StreamArnFor[EventType],
withIsTest: EventType => { val isTest: Boolean },
): Option[EventType] = ???
}
Running the method with StreamArnFor
in scope works properly
Workaround 2
Removing partitionKey: Option[String] = None
makes the initial version compile without changing the parameter ordering