Skip to content

Commit

Permalink
fix[ux]: fix uses error message (#3926)
Browse files Browse the repository at this point in the history
when a stateless module is accidentally declared as being `used` by a
user, the error message is confusing. update the error message to
clarify `uses` refers to state being used.
  • Loading branch information
charles-cooper authored Apr 10, 2024
1 parent b2db399 commit 8697519
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
8 changes: 6 additions & 2 deletions tests/functional/syntax/modules/test_initializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -915,7 +915,9 @@ def foo():

with pytest.raises(BorrowException) as e:
compile_code(main, input_bundle=input_bundle)
assert e.value._message == "`lib1` is declared as used, but it is not actually used in lib2.vy!"
expected = "`lib1` is declared as used, but its state is not"
expected += " actually used in lib2.vy!"
assert e.value._message == expected
assert e.value._hint == "delete `uses: lib1`"


Expand Down Expand Up @@ -956,7 +958,9 @@ def foo():

with pytest.raises(BorrowException) as e:
compile_code(main, input_bundle=input_bundle)
assert e.value._message == "`lib1` is declared as used, but it is not actually used in lib2.vy!"
expected = "`lib1` is declared as used, but its state is not "
expected += "actually used in lib2.vy!"
assert e.value._message == expected
assert e.value._hint == "delete `uses: lib1`"


Expand Down
2 changes: 1 addition & 1 deletion vyper/semantics/analysis/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ def validate_used_modules(self):
err_list = ExceptionList()
for used_module_info, uses_info in should_use.values():
msg = f"`{used_module_info.alias}` is declared as used, but "
msg += f"it is not actually used in {module_t}!"
msg += f"its state is not actually used in {module_t}!"
hint = f"delete `uses: {used_module_info.alias}`"
err_list.append(BorrowException(msg, uses_info.node, hint=hint))

Expand Down

0 comments on commit 8697519

Please sign in to comment.