From 831b3b2d5d1578e47c531f2dc62ed0b3df4180e0 Mon Sep 17 00:00:00 2001 From: Tigran Avagyan <60320285+Tiko7454@users.noreply.github.com> Date: Wed, 7 Jun 2023 22:00:15 +0400 Subject: [PATCH] local variable location fix (#1942) * Local variable location fix When we had a function f() which returns a pair, the result passed to local variables didn't initialize the location attribute. For example: contract A { function f() public returns (int, bytes memory) { return (1, "asdf"); } function g() public { (int x, bytes memory y) = f(); } } the location of the local variable x as well as the location of the local variable y was None * moved the fixes to the proper file * removed useless newlines --- .../local_variable_init_from_tuple.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/slither/solc_parsing/variables/local_variable_init_from_tuple.py b/slither/solc_parsing/variables/local_variable_init_from_tuple.py index 1a551c695..f1c872848 100644 --- a/slither/solc_parsing/variables/local_variable_init_from_tuple.py +++ b/slither/solc_parsing/variables/local_variable_init_from_tuple.py @@ -16,3 +16,21 @@ class LocalVariableInitFromTupleSolc(VariableDeclarationSolc): # Todo: Not sure how to overcome this with mypy assert isinstance(self._variable, LocalVariableInitFromTuple) return self._variable + + def _analyze_variable_attributes(self, attributes: Dict) -> None: + """' + Variable Location + Can be storage/memory or default + """ + if "storageLocation" in attributes: + location = attributes["storageLocation"] + self.underlying_variable.set_location(location) + else: + if "memory" in attributes["type"]: + self.underlying_variable.set_location("memory") + elif "storage" in attributes["type"]: + self.underlying_variable.set_location("storage") + else: + self.underlying_variable.set_location("default") + + super()._analyze_variable_attributes(attributes)