Vyper: Unhandled error in my code

Created on 24 Nov 2020  路  3Comments  路  Source: vyperlang/vyper

Version Information

  • vyper Version (output of vyper --version): 0.2.4
  • Compiler: online (not local)

What's your issue about?

I have the code below for one of my assignments which gives an unhandled error.

# @version ^0.2.4
owner: public(address)
target: public(uint256)
endTime: public(uint256)

Idx: public(uint256)
struct Contributor:
    userAddress: address
    contribution: uint256
contributors: Contributor[100]

@external
@payable
def __init__(_target: uint256, _duration: uint256):
    self.owner = msg.sender
    self.target = _target
    self.endTime = block.timestamp + _duration

@external
@payable
def contribute():
    assert block.timestamp < self.endTime, "Time to contribute is up!"
    self.contributors[self.Idx] = Contributor({userAddress: msg.sender, contribution: msg.value})
    self.Idx = self.Idx + 1

@external
def collect():
    assert self.balance >= self.target, "Target is not met, yet!"
    assert msg.sender == self.owner, "Only the owner can collect the fund."
    selfdestruct(self.owner)

@external
def refund():
    assert block.timestamp > self.endTime, "Money won't be refunded within the contract duration."
    assert self.balance < self.target, "Target is met and the fund is waiting to be collected."
    for contributor in self.contributors:
        send(contributor.userAddress,contributor.contribution)

@view
@external
def show_balance()-> uint256: 
    return self.balance

Remix won't return anything useful. Using etherscan online compiler I see this:

Err. RefID: vyper-in-bMRb4j8v94XWZgU.vy
vyper.exceptions.TypeCheckFailure: Statement node did not produce LLL

This is an unhandled internal compiler error. Please create an issue on Github to notify the developers.
https://github.com/vyperlang/vyper/issues/new?template=bug.md

How can it be fixed?

I haven't found the issue of my code, yet!

bug

All 3 comments

hey @domrany64, your issue is likely with the following line in refund():

    for contributor in self.contributors:
        send(contributor.userAddress,contributor.contribution)

It's not possible to iterate over a static list of a complex type yet, our type checking didn't catch this condition to report it properly. This should work for you:

    for i in range(LEN_CONTRIBUTORS):  # Note: use this constant above too (instead of `100`)
        send(self.contributors[i].userAddress, self.contributors[i].contribution)

We will work on the error message, and eventually add the ability to do this type of iteration

Wow, that was an easy fix.
Thank you for your help.

I hope the report has been helpful to you, too.

It was! Thank you for reporting!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ben-kaufman picture ben-kaufman  路  3Comments

pipermerriam picture pipermerriam  路  3Comments

travs picture travs  路  3Comments

michwill picture michwill  路  3Comments

fubuloubu picture fubuloubu  路  3Comments