Skip to content

Commit

Permalink
local variable location fix (#1942)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
Tiko7454 authored Jun 7, 2023
1 parent 79ff12a commit 831b3b2
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions slither/solc_parsing/variables/local_variable_init_from_tuple.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,21 @@ def underlying_variable(self) -> LocalVariableInitFromTuple:
# 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)

0 comments on commit 831b3b2

Please sign in to comment.