Skip to content

Commit 24ac428

Browse files
reject empty interfaces
1 parent 4986b50 commit 24ac428

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

tests/functional/syntax/modules/test_exports.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -466,3 +466,19 @@ def __init__():
466466
with pytest.raises(InterfaceViolation) as e:
467467
compile_code(main, input_bundle=input_bundle)
468468
assert e.value._message == "requested `lib1.ifoo` but `lib1` does not implement `lib1.ifoo`!"
469+
470+
471+
def test_export_empty_interface(make_input_bundle):
472+
lib1 = """
473+
def an_internal_function():
474+
pass
475+
"""
476+
main = """
477+
import lib1
478+
479+
exports: lib1.__interface__
480+
"""
481+
input_bundle = make_input_bundle({"lib1.vy": lib1})
482+
with pytest.raises(StructureException) as e:
483+
compile_code(main, input_bundle=input_bundle)
484+
assert e.value._message == "lib1 has no external functions!"

vyper/semantics/analysis/base.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ class AnalysisResult:
9696
class ModuleInfo(AnalysisResult):
9797
module_t: "ModuleT"
9898
alias: str
99+
# import_node: vy_ast._ImportStmt # maybe could be useful
99100
ownership: ModuleOwnership = ModuleOwnership.NO_OWNERSHIP
100101
ownership_decl: Optional[vy_ast.VyperNode] = None
101102

vyper/semantics/analysis/module.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -528,6 +528,12 @@ def visit_ExportsDecl(self, node):
528528
for fn in interface_t.functions.values()
529529
if fn.is_external
530530
]
531+
532+
if len(funcs) == 0:
533+
path = module_info.module_node.path
534+
msg = f"{module_info.alias} (located at `{path}`) has no external functions!"
535+
raise StructureException(msg, item)
536+
531537
else:
532538
raise StructureException(
533539
f"not a function or interface: `{info.typ}`", info.typ.decl_node, item

0 commit comments

Comments
 (0)