Skip to content

Commit

Permalink
reject empty interfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
charles-cooper committed Oct 19, 2024
1 parent 4986b50 commit 24ac428
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
16 changes: 16 additions & 0 deletions tests/functional/syntax/modules/test_exports.py
Original file line number Diff line number Diff line change
Expand Up @@ -466,3 +466,19 @@ def __init__():
with pytest.raises(InterfaceViolation) as e:
compile_code(main, input_bundle=input_bundle)
assert e.value._message == "requested `lib1.ifoo` but `lib1` does not implement `lib1.ifoo`!"


def test_export_empty_interface(make_input_bundle):
lib1 = """
def an_internal_function():
pass
"""
main = """
import lib1
exports: lib1.__interface__
"""
input_bundle = make_input_bundle({"lib1.vy": lib1})
with pytest.raises(StructureException) as e:
compile_code(main, input_bundle=input_bundle)
assert e.value._message == "lib1 has no external functions!"
1 change: 1 addition & 0 deletions vyper/semantics/analysis/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ class AnalysisResult:
class ModuleInfo(AnalysisResult):
module_t: "ModuleT"
alias: str
# import_node: vy_ast._ImportStmt # maybe could be useful
ownership: ModuleOwnership = ModuleOwnership.NO_OWNERSHIP
ownership_decl: Optional[vy_ast.VyperNode] = None

Expand Down
6 changes: 6 additions & 0 deletions vyper/semantics/analysis/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,12 @@ def visit_ExportsDecl(self, node):
for fn in interface_t.functions.values()
if fn.is_external
]

if len(funcs) == 0:
path = module_info.module_node.path
msg = f"{module_info.alias} (located at `{path}`) has no external functions!"
raise StructureException(msg, item)

else:
raise StructureException(
f"not a function or interface: `{info.typ}`", info.typ.decl_node, item
Expand Down

0 comments on commit 24ac428

Please sign in to comment.