diff --git a/tests/parser/syntax/test_functions_call.py b/tests/parser/syntax/test_functions_call.py index 144de06b76..f72b9a83a1 100644 --- a/tests/parser/syntax/test_functions_call.py +++ b/tests/parser/syntax/test_functions_call.py @@ -54,6 +54,20 @@ def test_functions_call_fail(bad_code): @public def foo() -> uint256: return convert(2, uint256) + """, + """ +from vyper.interfaces import ERC20 + +contract Factory: + def getExchange(token_addr: address) -> address: constant + +token: ERC20 +factory: Factory + +@public +def setup(token_addr: address): + self.token = ERC20(token_addr) + assert self.factory.getExchange(self.token) == self """ ] diff --git a/vyper/parser/parser_utils.py b/vyper/parser/parser_utils.py index ed9b4d88a6..9ca2a999c5 100644 --- a/vyper/parser/parser_utils.py +++ b/vyper/parser/parser_utils.py @@ -28,6 +28,9 @@ has_dynamic_data, is_base_type, ) +from vyper.types.types import ( + ContractType, +) from vyper.typing import ( ClassTypes, ) @@ -372,6 +375,8 @@ def base_type_conversion(orig, frm, to, pos, in_function_call=False): ) elif is_base_type(frm, to.typ) and are_units_compatible(frm, to): return LLLnode(orig.value, orig.args, typ=to, add_gas_estimate=orig.add_gas_estimate) + elif isinstance(frm, ContractType) and to == BaseType('address'): + return LLLnode(orig.value, orig.args, typ=to, add_gas_estimate=orig.add_gas_estimate) elif is_valid_int128_to_decimal: return LLLnode.from_list( ['mul', orig, DECIMAL_DIVISOR], diff --git a/vyper/types/types.py b/vyper/types/types.py index 21bb5228cb..d0a94840c0 100644 --- a/vyper/types/types.py +++ b/vyper/types/types.py @@ -409,7 +409,7 @@ def parse_type(item, location, sigs=None, custom_units=None, custom_structs=None if not isinstance(item.func, ast.Name): raise InvalidTypeException("Malformed unit type:", item) base_type = item.func.id - if base_type not in ('int128', 'uint256', 'decimal'): + if base_type not in ('int128', 'uint256', 'decimal', 'address'): raise InvalidTypeException("You must use int128, uint256, decimal, address, contract, \ for variable declarations and indexed for logging topics ", item) if len(item.args) == 0: