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

Provide useful error for "Cannot find trait Hash in this scope" #5293

Merged
merged 10 commits into from
Nov 22, 2023

Conversation

ironcev
Copy link
Member

@ironcev ironcev commented Nov 20, 2023

Description

This PR closes #5129 by providing a detailed guidelines to programmers on how to fix the "Cannot find trait XYZ in this scope". The issue is very prominent in the case of the Hash trait as demonstrated in the #5084.

We need to guide programmers at the moment because fixing the root cause will take some time. (Changes need to fix the root cause are sketched in this comment).

The PR:

  • replaces the current two misleading and redundant error messages with a clear instruction how to fix the issue at the call site.
  • provides the guidelines in a general case, and not only for the prominent issue with the Hash trait.
  • removes the redundant SymbolNotFound duplicated error and leaves only the specific TraitNotFound

Closes #5129.

Demo

These were the original redundant and misleading error messages produced at the function definition side:

image

This is the new error message:

image

In the case of an ambiguous trait, a detailed instructions are provided on how to find and import the required trait:

image

Checklist

  • I have linked to any relevant issues.
  • I have commented my code, particularly in hard-to-understand areas.
  • I have updated the documentation where relevant (API docs, the reference, and the Sway book).
  • I have added tests that prove my fix is effective or that my feature works.
  • I have added (or requested a maintainer to add) the necessary Breaking* or New Feature labels where relevant.
  • I have done my best to ensure that my PR adheres to the Fuel Labs Code Review Standards.
  • I have requested a review from the relevant team or maintainers.

@ironcev ironcev self-assigned this Nov 20, 2023
@ironcev ironcev added compiler General compiler. Should eventually become more specific as the issue is triaged compiler: frontend Everything to do with type checking, control flow analysis, and everything between parsing and IRgen labels Nov 20, 2023
@ironcev ironcev marked this pull request as ready for review November 21, 2023 10:19
@ironcev ironcev requested review from a team November 21, 2023 10:19
Copy link
Member

@sdankel sdankel left a comment

Choose a reason for hiding this comment

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

LGTM 🚀

@tritao tritao merged commit fdde5fd into master Nov 22, 2023
32 checks passed
@tritao tritao deleted the ironcev/5129-cannot-find-trait-hash branch November 22, 2023 20:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler: frontend Everything to do with type checking, control flow analysis, and everything between parsing and IRgen compiler General compiler. Should eventually become more specific as the issue is triaged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Provide temporary fix for the "Cannot find trait Hash in this scope" issue
3 participants