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

Improve asExprOf cast error formatting #19195

Merged

Conversation

nicolasstucki
Copy link
Contributor

The intention of this change is to make it simpler to read the error message.

List the expected type and actual type before the expression. This is usually the most important information and simpler to parse as the expression can get quite long. For the expected type, the actual type and the expression, we print the value in the same line if its String representation has only one line. Otherwise we print it in the next line with an indentation and extra new line at the end.

Before:

java.lang.Exception: Expr cast exception: ((a: scala.Int) => ({
  val v: scala.Int = a
  Binding.apply[scala.Unit](())
}: Binding[scala.Unit]))
of type: scala.Function1[scala.Int, scala.Unit]
did not conform to type: scala.Function1[scala.Int, Binding[scala.Unit]]

    at scala.quoted.runtime.impl.QuotesImpl.asExprOf(QuotesImpl.scala:76)
    ...

Example from #19191

After:

scala.quoted.runtime.impl.ExprCastException:
  Expected type: scala.Function1[scala.Int, scala.Unit]
  Actual type: scala.Function1[scala.Int, Binding[scala.Unit]]
  Expression:
    ((a: scala.Int) => ({
      val v: scala.Int = a
      Binding.apply[scala.Unit](())
    }: Binding[scala.Unit]))

    at scala.quoted.runtime.impl.QuotesImpl.asExprOf(QuotesImpl.scala:...)
    ...

The intention of this change is to make it simpler to read the error
message.

List the expected type and actual type before the expression. This
is usually the most important information and simpler to parse as the
expression can get quite long. For the expected type, the actual type
and the expression, we print the value in the same line if its String
representation has only one line. Otherwise we print it in the next line
with an indentation and extra new line at the end.

Before:
```
java.lang.Exception: Expr cast exception: ((a: scala.Int) => ({
  val v: scala.Int = a
  Binding.apply[scala.Unit](())
}: Binding[scala.Unit]))
of type: scala.Function1[scala.Int, scala.Unit]
did not conform to type: scala.Function1[scala.Int, Binding[scala.Unit]]

    at scala.quoted.runtime.impl.QuotesImpl.asExprOf(QuotesImpl.scala:76)
    ...
```

After:
```
scala.quoted.runtime.impl.ExprCastException:
  Expected type: scala.Function1[scala.Int, scala.Unit]
  Actual type: scala.Function1[scala.Int, Binding[scala.Unit]]
  Expression:
    ((a: scala.Int) => ({
      val v: scala.Int = a
      Binding.apply[scala.Unit](())
    }: Binding[scala.Unit]))

    at scala.quoted.runtime.impl.QuotesImpl.asExprOf(QuotesImpl.scala:...)
    ...
```
@WojciechMazur WojciechMazur merged commit 7480582 into scala:main Dec 5, 2023
19 checks passed
@Kordyjan Kordyjan added this to the 3.4.0 milestone Dec 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants