From 22a3ddbcc7add994299b51d2d14dafaa696a5a3c Mon Sep 17 00:00:00 2001 From: Ben Hauser Date: Fri, 27 Nov 2020 03:13:43 +0400 Subject: [PATCH 1/2] feat: lift restriction on calldata vars shadowing storage --- vyper/context/types/function.py | 2 -- .../function_definitions/parse_external_function.py | 8 -------- 2 files changed, 10 deletions(-) diff --git a/vyper/context/types/function.py b/vyper/context/types/function.py index 3e5dc5fc85..4edf35d480 100644 --- a/vyper/context/types/function.py +++ b/vyper/context/types/function.py @@ -280,8 +280,6 @@ def from_FunctionDef( ) if arg.arg in arguments: raise ArgumentException(f"Function contains multiple inputs named {arg.arg}", arg) - if arg.arg in namespace["self"].members: - raise NamespaceCollision("Name shadows an existing storage-scoped value", arg) if arg.arg in namespace: raise NamespaceCollision(arg.arg, arg) diff --git a/vyper/parser/function_definitions/parse_external_function.py b/vyper/parser/function_definitions/parse_external_function.py index 1e22af7107..6a59216e47 100644 --- a/vyper/parser/function_definitions/parse_external_function.py +++ b/vyper/parser/function_definitions/parse_external_function.py @@ -45,14 +45,6 @@ def validate_external_function( "__init__ function may not have default parameters.", code ) - # Check for duplicate variables with globals - for arg in sig.args: - if arg.name in global_ctx._globals: - raise FunctionDeclarationException( - "Variable name duplicated between " "function arguments and globals: " + arg.name, - code, - ) - def parse_external_function( code: ast.FunctionDef, sig: FunctionSignature, context: Context, is_contract_payable: bool From 23db60d9ac0d92d8106cd935f8bd6a10f623e171 Mon Sep 17 00:00:00 2001 From: Ben Hauser Date: Fri, 27 Nov 2020 05:17:39 +0400 Subject: [PATCH 2/2] test: add passing cases to check shadowing --- .../exceptions/test_namespace_collision.py | 28 +++++++++++++++---- 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/tests/parser/exceptions/test_namespace_collision.py b/tests/parser/exceptions/test_namespace_collision.py index c0b0e6db29..7497a25cb3 100644 --- a/tests/parser/exceptions/test_namespace_collision.py +++ b/tests/parser/exceptions/test_namespace_collision.py @@ -26,12 +26,6 @@ def foo(): """, """ x: int128 - -@external -def foo(x: int128): pass - """, - """ -x: int128 x: int128 """, """ @@ -60,3 +54,25 @@ def foo(): def test_insufficient_arguments(bad_code): with pytest.raises(NamespaceCollision): compiler.compile_code(bad_code) + + +pass_list = [ + """ +x: int128 + +@external +def foo(x: int128): pass + """, + """ +x: int128 + +@external +def foo(): + x: int128 = 1234 + """, +] + + +@pytest.mark.parametrize("code", pass_list) +def test_valid(code): + compiler.compile_code(code)