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

Unit Mismatch error for wei_value operation #1065

Closed
eltNEG opened this issue Nov 7, 2018 · 2 comments
Closed

Unit Mismatch error for wei_value operation #1065

eltNEG opened this issue Nov 7, 2018 · 2 comments
Labels
bug Bug that shouldn't change language semantics when fixed.

Comments

@eltNEG
Copy link

eltNEG commented Nov 7, 2018

Version Information

  • vyper Version: https://vyper.online [Wednesday, November 7, 2018]
    and
  • vyper Version: 0.1.0b4
  • pyethereum Version: x.x.x
  • OS: linux
  • Python Version (python --version): 3.6.6

What's your issue about?

Unexpected error while compiling my contract. Check the second to the last line in the snippet below
ERROR: vyper.exceptions.TypeMismatchException: line 177:8 Unit mismatch: {'wei': 1} {}
Why do I need to convert amount to wei_value again when it has already been declared in the function argument?
Code:

@public
@constant
def func(amounts: wei_value[100]) -> bool:
    total: wei_value = as_wei_value(0, "wei")

    # calculate total
    for amount in amounts:
        total += amount # Error: mismatch units

    return True

How can it be fixed?

Convert amount to wei_value

@public
@constant
def func(amounts: wei_value[100]) -> bool:
    total: wei_value = as_wei_value(0, "wei")
    
    for amount in amounts:
        total = as_wei_value(amount, "wei") # No error
    return True

Cute Animal Picture

cute animal picture

@eltNEG eltNEG changed the title Unit Mismatch error (vyper.online compiler) Unit Mismatch error for wei_value operation Nov 7, 2018
@fubuloubu
Copy link
Member

fubuloubu commented Nov 7, 2018

Ah, great catch. #1054 should probably account for this. What do you think @jacquesww? (Iterators should carry types and units)

Edit: wait, 1054 doesn't make sense. I think there is an earlier PR for Iterators

@jacqueswww jacqueswww added the bug Bug that shouldn't change language semantics when fixed. label Nov 14, 2018
@jacqueswww
Copy link
Contributor

Starting on this.

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

No branches or pull requests

3 participants