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

feat[lang]: reject implements for empty interfaces #4322

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions tests/functional/syntax/modules/test_implements.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import pytest

from vyper.compiler import compile_code
from vyper.exceptions import StructureException


def test_implements_from_vyi(make_input_bundle):
Expand Down Expand Up @@ -49,3 +52,21 @@ def foo(): # implementation
input_bundle = make_input_bundle({"some_interface.vyi": vyi, "lib1.vy": lib1, "lib2.vy": lib2})

assert compile_code(main, input_bundle=input_bundle) is not None


def test_implements_empty_vyi(make_input_bundle, tmp_path):
vyi = ""
input_bundle = make_input_bundle({"some_interface.vyi": vyi})
main = """
import some_interface

implements: some_interface
"""
with pytest.raises(StructureException) as e:
_ = compile_code(main, input_bundle=input_bundle)

vyi_path = (tmp_path / "some_interface.vyi").as_posix()
assert (
e.value._message
== f"Tried to implement `{vyi_path}`, but it has no functions to implement!"
)
4 changes: 4 additions & 0 deletions vyper/semantics/types/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@ def _ctor_modifiability_for_call(self, node: vy_ast.Call, modifiability: Modifia
def validate_implements(
self, node: vy_ast.ImplementsDecl, functions: dict[ContractFunctionT, vy_ast.VyperNode]
) -> None:
if len(self.functions) == 0:
msg = f"Tried to implement `{self}`, but it has no functions to implement!"
raise StructureException(msg, node)

# only external functions can implement interfaces
fns_by_name = {fn_t.name: fn_t for fn_t in functions.keys()}

Expand Down
Loading