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
pull/1990/head
Tigran Avagyan 1 year ago committed by GitHub
parent 79ff12a5e2
commit 831b3b2d5d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 18
      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)

Loading…
Cancel
Save