Vyper: Unclear ambiguous type error

Created on 19 Aug 2020  路  1Comment  路  Source: vyperlang/vyper

Version Information

  • vyper Version (output of vyper --version): 0.2.4+commit.7949850
  • OS: linux
  • Python Version (output of python --version): Python 3.7.3
  • Environment (output of pip freeze):
    asttokens==2.0.3
    pycryptodome==3.9.8
    semantic-version==2.8.5
    six==1.15.0
    vyper==0.2.4

What's your issue about?

Unclear ambiguous type error on a simple code.

# @version 0.2.4
from vyper.interfaces import ERC20

coins: constant(address[4]) = [
    0x6B175474E89094C44Da98b954EedeAC495271d0F,
    0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48,
    0xdAC17F958D2ee523a2206206994597C13D831ec7,
    0x0000000000085d4780B73119b644AE5ecd22b376,
]

@external
def recycle():
    balances: uint256[4] = empty(uint256[4])
    for i in range(4):
        balances[i] = ERC20(coins[i]).balanceOf(msg.sender)
StructureException: Ambiguous type
  contract "contracts/Recycle.vy", function "recycle", line 31:28
       30     for i in range(4):
  ---> 31         balances[i] = ERC20(coins[i]).balanceOf(msg.sender)
  ------------------------------------^

How can it be fixed?

You tell me

bug

Most helpful comment

Looks like constant folding is the issue... coins[i] ends up changed to [0x6B175474E89094C44Da98b954EedeAC495271d0F, 0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48, 0xdAC17F958D2ee523a2206206994597C13D831ec7, 0x0000000000085d4780B73119b644AE5ecd22b376][i] and the type checker gets confused if it's looking at an address[4] or a Bytes[20][4].

I see two issues to address here:

  1. We need to properly differentiate between address and bytes types when folding.
  2. The "Ambiguous type" error should explain which types it's seeing, so that the problem is easier to diagnose.

>All comments

Looks like constant folding is the issue... coins[i] ends up changed to [0x6B175474E89094C44Da98b954EedeAC495271d0F, 0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48, 0xdAC17F958D2ee523a2206206994597C13D831ec7, 0x0000000000085d4780B73119b644AE5ecd22b376][i] and the type checker gets confused if it's looking at an address[4] or a Bytes[20][4].

I see two issues to address here:

  1. We need to properly differentiate between address and bytes types when folding.
  2. The "Ambiguous type" error should explain which types it's seeing, so that the problem is easier to diagnose.
Was this page helpful?
0 / 5 - 0 ratings

Related issues

fubuloubu picture fubuloubu  路  3Comments

jacqueswww picture jacqueswww  路  4Comments

jacqueswww picture jacqueswww  路  3Comments

vici0 picture vici0  路  3Comments

ben-kaufman picture ben-kaufman  路  3Comments