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 13 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 degrade performances by 50.4%

Comparing xunilrj/error-contract-method-conflict (72a8ed4) with master (faf399e)

Summary

❌ 2 regressions
✅ 20 untouched benchmarks

⚠️ Please fix the performance issues or acknowledge them on CodSpeed.

Benchmarks breakdown

Benchmark master xunilrj/error-contract-method-conflict Change
traverse 212.9 ms 388.4 ms -45.19%
code_lens 5.4 µs 11 µs -50.4%

@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 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

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.

5 participants