Open pcaversaccio opened 1 year ago
Another example, where this behavior would be useful:
@external
def example_fn(asset_: ERC20):
success: bool = empty(bool)
return_data: Bytes[max_value(uint8)] = b""
success, return_data = raw_call(asset_, ...)
To fix it currently, I must use .address
again:
@external
def example_fn(asset_: ERC20):
success: bool = empty(bool)
return_data: Bytes[max_value(uint8)] = b""
success, return_data = raw_call(asset_.address, ...)
sorry i think i forgot to comment on this -- i think the issue here is the error message is confusing, but there are not implicit type conversions going on. there is no convert()
role between interfaces and addresses, you just use <some contract>.address
sorry i think i forgot to comment on this -- i think the issue here is the error message is confusing, but there are not implicit type conversions going on. there is no
convert()
role between interfaces and addresses, you just use<some contract>.address
as per offline discussion, it's worth adding that the Vyper convention in the ABI encoding is to represent an interface as address
. We should get the confusing error message fixed.
Version Information
vyper --version
):0.3.7+commit.6020b8b
python --version
):3.9.2
What's your issue about?
Interface type returns implicitly but not explicitly type
address
at assignment.Let me explain what I exactly mean. Let's start with the following snippet (let's call it
contract.vy
):Using Titanoboa, we can simply do the following:
So the compiler returns implicitly the result of
asset_.address
at construction time. However, the compiler will throw withvyper.exceptions.TypeMismatch: Given reference has type ERC20, expected address
if I make an explicitaddress
type assignment:Ok, so far so good, but if I add a conversion to
address
it will throw withvyper.exceptions.TypeMismatch: Can't convert address to address
So under the hood, the compiler already assigns the type
address
but does still not allow for an explicitaddress
assignment, but requires the typeERC20
(or fix it viaasset_.address
). At least for me the feels kinda inconsistent.How can it be fixed?
Allow for the following and the compiler automatically handles the assignment of
asset_.address
: