Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect error message due to ordering of givens in using clause #22917

Open
majk-p opened this issue Apr 4, 2025 · 3 comments
Open

Incorrect error message due to ordering of givens in using clause #22917

majk-p opened this issue Apr 4, 2025 · 3 comments
Labels
area:implicits related to implicits itype:bug

Comments

@majk-p
Copy link

majk-p commented Apr 4, 2025

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

@majk-p majk-p added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels Apr 4, 2025
@som-snytt
Copy link
Contributor

som-snytt commented Apr 4, 2025

3.nightly says (or 3.7.0-RC1) (Edit: for the minimized gist)

32 |  api.expect(MyEvent){ (event: MyEvent) => event.id.nonEmpty }
   |                                                              ^
   |No given instance of type StreamArnFor[MyEvent] was found for parameter streamArnFor of method expect in object api
1 error found
Compilation failed

@majk-p
Copy link
Author

majk-p commented Apr 4, 2025

For both snippets?

@som-snytt
Copy link
Contributor

Maybe due to c37dc8b ?

This commit restores propagatedFailure...

@Gedochao Gedochao added area:implicits related to implicits and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels Apr 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:implicits related to implicits itype:bug
Projects
None yet
Development

No branches or pull requests

3 participants