Skip to content

Fix/18681 unreduced summon from fallback #19490

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

i10416
Copy link
Contributor

@i10416 i10416 commented Jan 19, 2024

fix #18681

This commit fixes the reporting issue where un-reduced summonFrom does not fallback to implicitNotFound.

Before this commit, reduceInlineMatch discarded the information from implicit search in InlineReducer.

See https://github.com/lampepfl/dotty/pull/19490/files#diff-b34b7edb06dcd7e56dac607175a9519e98d79473371201ad3c750613db3a8579R207-R213

This commit adds some changes so that the error message from implicit search failure can propagate to
Inliner#typedMatchFinish to emit better error message.

This commit fixes the reporting issue where un-reduced summonFrom does not fallback to implicitNotFound.

Before this commit, `reduceInlineMatch` discarded the information from
implicit search in InlineReducer. This commit adds some changes so that
the error message from implicit search failure can propagate to
Inliner#typedMatchFinish to emit better error message.
case _ => None
}
case Left(None) => recur(cases1, theLastMsg)
case Left(msg @Some(_)) => recur(cases1, msg)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should it fail fast when a case results in missing implicit instance rather than continuing remaining cases?

@i10416 i10416 changed the title Fix/18681 un reduced summon from fallback Fix/18681 unreduced summon from fallback Jan 19, 2024
@nicolasstucki nicolasstucki self-assigned this Jan 23, 2024

inline def summonMissing = compiletime.summonFrom {
case m: Missing => m
}
Copy link
Contributor

@nicolasstucki nicolasstucki Jan 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder what should be the error for

@annotation.implicitNotFound("there is no Missing1!")
trait Missing1
@annotation.implicitNotFound("there is no Missing2!")
trait Missing2
inline def summonMissing = compiletime.summonFrom {
  case m: Missing1 => m
  case m: Missing2 => m
}
val x = summonMissing

We can choose the first one, last one, concatenate the messages. Not sure what would be best. This might also mean that we loose information in which implicits are accepted here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In that case it might be better to do

inline def summonMissing = compiletime.summonFrom {
  case m: Missing1 => m
  case m: Missing2 => m
  case _ => compiletime.error("no Missing1 or Missing2 found")
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently I think that we should use compiletime.error over implicitNotFound. The error messages in the implicitNotFound usually assume that this is the only implicit beeing summoned. Reusing implicitNotFound might lead to error messages that are out of context.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, I also wonder which error message(s) it should show.

I choosed the last message rather than accumulating errors with the aim of minimizing diff in the dotty codebase.

Copy link
Contributor Author

@i10416 i10416 Jan 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reusing ... that are out of context

I agree with you. If we concat multiple implicitNotFounds that encourage users to import something at the same time, users could follow the instruction only to find ambiguous implicits, which could confuse users, but suggest all the possible actions they can take.

Copy link
Contributor Author

@i10416 i10416 Jan 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After all, it feels reasonable to keep the current behavior, doesn't it?

Should/Could we report unexhaustiveness as error in summonFrom with an error message better than "cannot reduce summonFrom with ..." in the similar way as we warn on unexhaustive pattern matches to enums?
(e.g. This does not compile because no instance of Missing1 or Missing2 is found.)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reminiscent of implicitNotFound on parent classes. IIRC scala 2 appends (accumulates); there is an open dotty ticket.

Copy link
Contributor Author

@i10416 i10416 Jan 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you think it is better to keep unreduced summon from... to prevent users from getting confused, I will close this PR and address other issues. Otherwise, I will add changes to accumulate error messages from implicitsNotFound annotations.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should/Could we report unexhaustiveness as error in summonFrom with an error message better than "cannot reduce summonFrom with ..." in the similar way as we warn on unexhaustive pattern matches to enums?
(e.g. This does not compile because no instance of Missing1 or Missing2 is found.)

That sounds like a better solution. I assume that we will still see the summonForm in the inlining stack trace. Therefore we would have a simple error message followed by the more detailed explanation.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the feedback. I'll address this.

@nicolasstucki nicolasstucki removed their assignment Apr 12, 2024
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.

un-reduced summonFrom does not fallback to implicitNotFound
3 participants