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

fix[ux]: error messages relating to initializer issues #3831

Merged

Conversation

charles-cooper
Copy link
Member

What I did

fix some error messages

How I did it

How to verify it

Commit message

Commit message for the final, squashed PR. (Optional, but reviewers will appreciate it! Please see our commit message style guide for what we would ideally like to see in a commit message.)

Description for the changelog

Cute Animal Picture

Put a link to a cute animal picture inside the parenthesis-->

@codecov-commenter
Copy link

codecov-commenter commented Mar 5, 2024

Codecov Report

Attention: Patch coverage is 90.47619% with 2 lines in your changes are missing coverage. Please review.

Project coverage is 90.76%. Comparing base (9d0d147) to head (2a29a9e).
Report is 1 commits behind head on master.

Files Patch % Lines
vyper/semantics/analysis/global_.py 50.00% 1 Missing and 1 partial ⚠️

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3831      +/-   ##
==========================================
- Coverage   90.92%   90.76%   -0.17%     
==========================================
  Files          95       95              
  Lines       14395    14411      +16     
  Branches     3187     3193       +6     
==========================================
- Hits        13089    13080       -9     
- Misses        906      927      +21     
- Partials      400      404       +4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

vyper/semantics/analysis/module.py Outdated Show resolved Hide resolved
vyper/semantics/analysis/module.py Show resolved Hide resolved
@charles-cooper charles-cooper mentioned this pull request Mar 6, 2024
33 tasks
Copy link
Member

@fubuloubu fubuloubu left a comment

Choose a reason for hiding this comment

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

Kind of a code smell that only one test changed with all of these updates

@cyberthirst
Copy link
Collaborator

consider:
main

import lib1
import lib2
import lib3

initializes: lib2[lib1:=lib1]
initializes: lib1
initializes: lib3

lib1

counter: uint256

lib3

counter: uint256

lib2

import lib1
import lib3

uses: lib1
uses: lib3

counter: uint256

@internal
def foo():
    lib1.counter += 1
    lib3.counter += 1

then:

vyper.exceptions.InitializerException: `lib2` uses `lib3`, but it is not initialized with `lib3`

  (hint: did you mean lib2[lib3 := lib3]?)

  contract "tests/custom/test4.vy:5", line 5:0 
       4
  ---> 5 initializes: lib2[lib1:=lib1]
  -------^
       6 initializes: lib1

ie the hint excludes the current lib1 intializer - initializes: lib2[lib1:=lib1]

break

if rhs is None:
hint = "try importing {item.alias} first"
Copy link
Collaborator

Choose a reason for hiding this comment

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

this should be an f-string, right

@charles-cooper
Copy link
Member Author

note: planning on changing the initializer syntax to look like lib[dep] instead of lib[dep := dep]

@charles-cooper
Copy link
Member Author

Kind of a code smell that only one test changed with all of these updates

it was missing tests for the new cases -- thanks @cyberthirst for help adding

@charles-cooper
Copy link
Member Author

note: planning on changing the initializer syntax to look like lib[dep] instead of lib[dep := dep]

after thinking about it i think this is kind of a non-issue, both syntaxes are kind of ok, because the latter syntax helps make it clear when you use lib.dep and the library imports it as a different name (e.g., lib[dependency := dep]). in this case if you access dep through the library (as lib.dependency) it's clearer that dep and lib.dependency are the same module. deciding on one syntax over the other is splitting hairs IMO. (there COULD be an argument that we should ban accessing dep through lib.dependency altogether. but i don't think it's a good time to revisit this so close to release, we can always revisit in a later release).

@pcaversaccio
Copy link
Collaborator

note: planning on changing the initializer syntax to look like lib[dep] instead of lib[dep := dep]

after thinking about it i think this is kind of a non-issue, both syntaxes are kind of ok, because the latter syntax helps make it clear when you use lib.dep and the library imports it as a different name (e.g., lib[dependency := dep]). in this case if you access dep through the library (as lib.dependency) it's clearer that dep and lib.dependency are the same module. deciding on one syntax over the other is splitting hairs IMO. (there COULD be an argument that we should ban accessing dep through lib.dependency altogether. but i don't think it's a good time to revisit this so close to release, we can always revisit in a later release).

FWIW, I use the lib[dep := dep] syntax in snekmate contract mocks; example:

# @dev We import and initialise the `Ownable` module.
from .. import Ownable as ow
initializes: ow


# @dev We import and initialise the `Ownable2Step` module.
from .. import Ownable2Step as o2
initializes: o2[ownable := ow]

@charles-cooper charles-cooper enabled auto-merge (squash) April 7, 2024 15:12
@charles-cooper charles-cooper merged commit c54d3b1 into vyperlang:master Apr 7, 2024
148 checks passed
electriclilies pushed a commit to electriclilies/vyper that referenced this pull request Apr 27, 2024
fix some error messages related to initializers, to improve UX

---------

Co-authored-by: cyberthirst <cyberthirst.eth@gmail.com>
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