Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ContractType address base_type_conversion #1373

Merged
merged 2 commits into from
Mar 30, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions tests/parser/syntax/test_functions_call.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
"""
]

Expand Down
5 changes: 5 additions & 0 deletions vyper/parser/parser_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
has_dynamic_data,
is_base_type,
)
from vyper.types.types import (
ContractType,
)
from vyper.typing import (
ClassTypes,
)
Expand Down Expand Up @@ -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],
Expand Down
2 changes: 1 addition & 1 deletion vyper/types/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down