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

Show error when contract method names conflict #6782

Open
wants to merge 17 commits into
base: master
Choose a base branch
from

Conversation

xunilrj
Copy link
Contributor

@xunilrj xunilrj commented Dec 10, 2024

Description

Today, contract call uses the method name to identify which contract method to call. That means that a contract cannot have multiple methods with the same name.

That can happen when a contract implements traits:

image

A lot of the lifetime changes were caused by clippy.

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.

Copy link

codspeed-hq bot commented Dec 10, 2024

CodSpeed Performance Report

Merging #6782 will not alter performance

Comparing xunilrj/error-contract-method-conflict (fedeb56) with master (4fe6870)

Summary

✅ 22 untouched benchmarks

@xunilrj xunilrj marked this pull request as ready for review December 16, 2024 15:57
@xunilrj xunilrj requested a review from a team as a code owner December 16, 2024 15:57
@xunilrj xunilrj self-assigned this Dec 16, 2024
@xunilrj xunilrj changed the title Error contract method conflict Show error when contract method names conflict Dec 16, 2024
@xunilrj xunilrj force-pushed the xunilrj/error-contract-method-conflict branch from ce06771 to 041975f Compare January 2, 2025 13:57
@xunilrj xunilrj requested a review from a team as a code owner January 2, 2025 14:27
@xunilrj xunilrj requested a review from sdankel January 2, 2025 16:24
sway-error/src/error.rs Outdated Show resolved Hide resolved
sdankel
sdankel previously approved these changes Jan 3, 2025
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, just one nit

@sdankel
Copy link
Member

sdankel commented Jan 4, 2025

Actually, I noticed that the new errors aren't being passed to LSP. You can test this by installing forc-plugins/forc-lsp and loading the test file in VSCode. The new errors do not show up in the editor. I'm still digging into it, but it looks like the errors aren't being emitted to the handler properly. When I log the handler at the end of sway-core/src/lib.rs parsed_to_ast, the errors vec is empty.

@xunilrj
Copy link
Contributor Author

xunilrj commented Jan 6, 2025

This happens because the LSP still compiles everything using encoding v0, and this check only runs for encoding v1. See https://github.com/FuelLabs/sway/blob/master/sway-lsp/src/core/session.rs#L323.

It used to be the case that LSP was not compatible with encoding v1. I am not sure this is still true.

IGI-111
IGI-111 previously approved these changes Jan 6, 2025
tritao
tritao previously approved these changes Jan 6, 2025
Copy link
Contributor

@tritao tritao left a comment

Choose a reason for hiding this comment

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

Looks good (aside from the nit from @sdankel)

@xunilrj
Copy link
Contributor Author

xunilrj commented Jan 6, 2025

When I enable the LSP to use encoding V1 (just removing from the no_experimental in session.rs), I see the diagnostic inside traverse. But typed at line 395, is Err(...), which I think is short-circuiting the processing of all the others diagnostics, and nothing is returned.

zees-dev
zees-dev previously approved these changes Jan 7, 2025
@xunilrj xunilrj dismissed stale reviews from tritao, IGI-111, sdankel, and zees-dev via 563b768 January 7, 2025 19:28
@xunilrj xunilrj force-pushed the xunilrj/error-contract-method-conflict branch from f858fae to 563b768 Compare January 7, 2025 19:28
@xunilrj
Copy link
Contributor Author

xunilrj commented Jan 7, 2025

I managed to improve what the compiler sends to the LSP server, and now the error is being displayed correctly.

image

@xunilrj xunilrj force-pushed the xunilrj/error-contract-method-conflict branch from 1a0cc4f to 32e183f Compare January 13, 2025 16:01
@xunilrj
Copy link
Contributor Author

xunilrj commented Jan 13, 2025

I have rollbacked part of the solution to enable encoding v1 in the LSP. The issue is a problem with the garbage collector. However, I am pushing the solution to improve how the LSP deals with compiler errors.

This means that when the compiler fails, it returns as much information as possible to the LSP server. Which is also using as much information as it can to enrich data for tokens.

In general, LSP should be able to show more diagnostics now. But unfortunately, it will not show the errors of this PR.

sdankel
sdankel previously approved these changes Jan 13, 2025
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.

🚀

Copy link
Member

@JoshuaBatty JoshuaBatty left a comment

Choose a reason for hiding this comment

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

Nice work @xunilrj , just a couple of small nits.

@JoshuaBatty JoshuaBatty requested review from a team January 14, 2025 23:37
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.

6 participants