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

uint256 doesn't work as array index #1478

Closed
scherrey opened this issue Jun 12, 2019 · 0 comments · Fixed by #1479
Closed

uint256 doesn't work as array index #1478

scherrey opened this issue Jun 12, 2019 · 0 comments · Fixed by #1479
Labels
bug Bug that shouldn't change language semantics when fixed.

Comments

@scherrey
Copy link

Version Information

  • vyper Version (output of vyper --version): 0.1.0b10
  • OS: linux Kubuntu 14.04 Linux satriani 4.9.119-first-custom lay an egg #1 SMP Mon Aug 13 18:33:19 +07 2018 x86_64 x86_64 x86_64 GNU/Linux
  • Python Version (output of python --version): 3.6.3
  • Environment (output of pip freeze):
    asn1crypto==0.24.0
    async-generator==1.10
    async-lru==0.1.0
    asyncio-cancel-token==0.1.0a2
    atomicwrites==1.3.0
    attrdict==2.0.1
    attrs==19.1.0
    backcall==0.1.0
    base58==1.0.3
    bloom-filter==1.3
    cached-property==1.5.1
    cachetools==3.1.1
    certifi==2019.3.9
    cffi==1.12.3
    chardet==3.0.4
    coincurve==10.0.0
    cryptography==2.7
    cypari==2.3.0
    cytoolz==0.9.0.1
    decorator==4.4.0
    eth-abi==2.0.0b9
    eth-account==0.4.0
    eth-bloom==1.0.3
    eth-hash==0.2.0
    eth-keyfile==0.5.1
    eth-keys==0.2.4
    eth-rlp==0.1.2
    eth-tester==0.1.0b39
    eth-typing==2.1.0
    eth-utils==1.6.1
    ethpm==0.1.4a19
    future==0.17.1
    FXrays==1.3.3
    hexbytes==0.2.0
    idna==2.8
    ifaddr==0.1.6
    importlib-metadata==0.18
    ipdb==0.12
    ipfshttpclient==0.4.12
    ipython==7.5.0
    ipython-genutils==0.2.0
    jedi==0.13.3
    jsonschema==2.6.0
    lahja==0.12.0
    lru-dict==1.1.6
    lxml==4.3.3
    more-itertools==7.0.0
    multiaddr==0.0.8
    mypy-extensions==0.4.1
    netaddr==0.7.19
    netdisco==2.6.0
    networkx==2.3
    packaging==19.0
    parsimonious==0.8.1
    parso==0.4.0
    pexpect==4.7.0
    pickleshare==0.7.5
    pipenv==2018.11.26
    plink==2.2
    pluggy==0.12.0
    plyvel==1.0.5
    prompt-toolkit==2.0.9
    protobuf==3.8.0
    ptyprocess==0.6.0
    py==1.8.0
    py-ecc==1.7.0
    py-evm==0.2.0a42
    py-geth==2.1.0
    pycparser==2.19
    pycryptodome==3.8.2
    pyethash==0.1.27
    Pygments==2.4.2
    pyparsing==2.4.0
    pypng==0.0.19
    pyrsistent==0.15.2
    pysha3==1.0.2
    pytest==4.6.3
    pytest-ethereum==0.1.3a6
    python-dateutil==2.8.0
    requests==2.22.0
    rlp==1.1.0
    semantic-version==2.6.0
    simplegeneric==0.8.1
    six==1.12.0
    snappy-manifolds==1.0
    spherogram==1.8.1
    SQLAlchemy==1.3.4
    toolz==0.9.0
    traitlets==4.3.2
    trie==1.4.0
    typing-extensions==3.7.2
    uPnPClient==0.0.8
    urllib3==1.25.3
    uvloop==0.11.2
    varint==1.0.2
    virtualenv==16.6.0
    virtualenv-clone==0.5.3
    vyper==0.1.0b10
    wcwidth==0.1.7
    web3==5.0.0b2
    websockets==7.0
    zeroconf==0.22.0
    zipp==0.5.1

What's your issue about?

Attempts to use uint256 as an index parameter into an array results in the following error:

vyper.exceptions.TypeMismatchException: line 207:8 Typecasting from base type uint256 to int128 unavailable

Example code:

MAX_AUCTION_ITEMS: constant(uint256)  = 5

tokenIds: uint256[MAX_AUCTION_ITEMS]
tokenQty: uint256 # Total number of tokenIds actually in the tokenIds list.



@public
def __init__(_token_ids: uint256[MAX_AUCTION_ITEMS], _kyc_provider: address, _start: timestamp, _end: timestamp):
    """
    _token_ids - a list of each UNIQUE tokenId in order of most valuable
    being the first in the list.

    _kyc_provider - wallet address of the account with rights to manage
    the approved bidder list.

    _start - the datetime when the auction can accept bids.

    _end - the datetime when the auction ends normal bidding activities.
    """

    # load up the tokenIds
    for tokenId in _token_ids:
        if tokenId == 0: break


        self.tokenIds[self.tokenQty] = tokenId ### vyper.exceptions.TypeMismatchException: line 207:8 Typecasting from base type uint256 to int128 unavailable

        
        self.tokenQty += 1    

How can it be fixed?

@charles-cooper figured out that the following work around get's us by:

self.tokenIds[convert(self.tokenQty, int128)] = tokenId

@jacqueswww jacqueswww added the bug Bug that shouldn't change language semantics when fixed. label Jun 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Bug that shouldn't change language semantics when fixed.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants