From f2db3448b1c17c41ba1e5e3e9dbbb79af6620b05 Mon Sep 17 00:00:00 2001 From: Charles Cooper Date: Mon, 12 Feb 2024 18:56:26 -0500 Subject: [PATCH 1/4] fix error message for `implements: module` currently, the compiler will panic when it encounters this case. add a suggestion to rename the interface file to `.vyi`. also catch all invalid types with a compiler panic. --- vyper/semantics/analysis/module.py | 10 +++++++++- vyper/semantics/types/utils.py | 6 ++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/vyper/semantics/analysis/module.py b/vyper/semantics/analysis/module.py index e50c3e6d6f..448621ea69 100644 --- a/vyper/semantics/analysis/module.py +++ b/vyper/semantics/analysis/module.py @@ -342,7 +342,15 @@ def visit_ImplementsDecl(self, node): type_ = type_from_annotation(node.annotation) if not isinstance(type_, InterfaceT): - raise StructureException("not an interface!", node.annotation) + msg = "Not an interface!" + hint = None + if isinstance(type_, ModuleT): + path = type_._module.path + msg += " (Since vyper v0.4.0, interface files are required" + msg += " to have a .vyi suffix.)" + #hint += f".vyi suffix.\n" + hint = f"try renaming `{path}` to `{path}i`" + raise StructureException(msg, node.annotation, hint=hint) type_.validate_implements(node) diff --git a/vyper/semantics/types/utils.py b/vyper/semantics/types/utils.py index c6a4531df8..ec16502ba2 100644 --- a/vyper/semantics/types/utils.py +++ b/vyper/semantics/types/utils.py @@ -158,6 +158,12 @@ def _type_from_annotation(node: vy_ast.VyperNode) -> VyperType: # call from_annotation to produce a better error message. typ_.from_annotation(node) + if hasattr(typ_, "module_t"): # it's a ModuleInfo + typ_ = typ_.module_t + + if not isinstance(typ_, VyperType): + raise CompilerPanic("Not a type: {typ_}", node) + return typ_ From 4ca2328b78be84a8602a0030b86994e66808cf0a Mon Sep 17 00:00:00 2001 From: Charles Cooper Date: Mon, 12 Feb 2024 19:04:23 -0500 Subject: [PATCH 2/4] add a helpful hint for imports from `vyper.interfaces` --- vyper/semantics/analysis/module.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/vyper/semantics/analysis/module.py b/vyper/semantics/analysis/module.py index 448621ea69..8fd0c2b74f 100644 --- a/vyper/semantics/analysis/module.py +++ b/vyper/semantics/analysis/module.py @@ -635,6 +635,9 @@ def _load_import(self, node: vy_ast.VyperNode, level: int, module_str: str, alia def _load_import_helper( self, node: vy_ast.VyperNode, level: int, module_str: str, alias: str ) -> Any: + if module_str.startswith("vyper.interfaces"): + hint = "try renaming `vyper.interfaces` to `ethereum.ercs`" + raise ModuleNotFound(module_str, hint=hint) if _is_builtin(module_str): return _load_builtin_import(level, module_str) @@ -732,7 +735,7 @@ def _is_builtin(module_str): def _load_builtin_import(level: int, module_str: str) -> InterfaceT: if not _is_builtin(module_str): - raise ModuleNotFoundError(f"Not a builtin: {module_str}") from None + raise ModuleNotFoundError(f"Not a builtin: {module_str}") builtins_path = vyper.builtins.interfaces.__path__[0] # hygiene: convert to relpath to avoid leaking user directory info From c5c8a7d9066e782407707a433d931306de088935 Mon Sep 17 00:00:00 2001 From: Charles Cooper Date: Mon, 12 Feb 2024 19:12:49 -0500 Subject: [PATCH 3/4] remove a comment --- vyper/semantics/analysis/module.py | 1 - 1 file changed, 1 deletion(-) diff --git a/vyper/semantics/analysis/module.py b/vyper/semantics/analysis/module.py index 8fd0c2b74f..9304eb3ded 100644 --- a/vyper/semantics/analysis/module.py +++ b/vyper/semantics/analysis/module.py @@ -348,7 +348,6 @@ def visit_ImplementsDecl(self, node): path = type_._module.path msg += " (Since vyper v0.4.0, interface files are required" msg += " to have a .vyi suffix.)" - #hint += f".vyi suffix.\n" hint = f"try renaming `{path}` to `{path}i`" raise StructureException(msg, node.annotation, hint=hint) From 0d2257231ea651e2c0e24425695446a6c701dba8 Mon Sep 17 00:00:00 2001 From: Charles Cooper Date: Mon, 12 Feb 2024 19:13:24 -0500 Subject: [PATCH 4/4] fix lint --- vyper/semantics/types/utils.py | 1 + 1 file changed, 1 insertion(+) diff --git a/vyper/semantics/types/utils.py b/vyper/semantics/types/utils.py index ec16502ba2..96c661021f 100644 --- a/vyper/semantics/types/utils.py +++ b/vyper/semantics/types/utils.py @@ -3,6 +3,7 @@ from vyper import ast as vy_ast from vyper.exceptions import ( ArrayIndexException, + CompilerPanic, InstantiationException, InvalidType, StructureException,