Vyper: AttributeError when raising on MappingType

Created on 30 Apr 2020  路  3Comments  路  Source: vyperlang/vyper

Version Information

  • vyper Version (output of vyper --version): 0.1.0b17

What's your issue about?

m: map(int128, uint256)

@public
def f():
    x: uint256 = self.m

raises

vyper/parser/stmt.py in _check_valid_assign(self, sub)
    141                 )
    142         # Check that the integer literal, can be assigned to uint256 if necessary.
--> 143         elif (self.stmt.annotation.id, sub.typ.typ) == ('uint256', 'int128') and sub.typ.is_literal:
    144             if not SizeLimits.in_bounds('uint256', sub.value):
    145                 raise InvalidLiteral(

AttributeError: 'MappingType' object has no attribute 'typ'

How can it be fixed?

Add a check if it's a MappingType, then raise (maps cannot be the target of a statement, directly)

Easy Pickings bug

All 3 comments

AttributeError is raised for all types that are not the subclass of _BaseType_ in vyper/types/types.py when they are assigned to the wrong type.
Except for struct type because there is already a check for it in vyper/parser/stmt.py

example_bytes: bytes[100] 

@public
def f():
    x: uint256 = self.example_bytes

raises

elif (self.stmt.annotation.id, sub.typ.typ) == ('uint256', 'int128') and sub.typ.is_literal:
AttributeError: 'ByteArrayType' object has no attribute 'typ'
exampleList: int128[3]

@public
def f():
    x: uint256 = self.exampleList

raises

    elif (self.stmt.annotation.id, sub.typ.typ) == ('uint256', 'int128') and sub.typ.is_literal:
AttributeError: 'ListType' object has no attribute 'typ'
example_str: string[100]

@public
def f():
    x: uint256 = self.example_str

raises

    elif (self.stmt.annotation.id, sub.typ.typ) == ('uint256', 'int128') and sub.typ.is_literal:
AttributeError: 'StringType' object has no attribute 'typ'

There has to be some kind of check to make sure that these are not being assigned incorrectly.

I think @iamdefinitelyahuman's type checker refactor will take care of this, but I wanted to keep this issue open for now while that is in progress.

Fixed by #2029

Was this page helpful?
0 / 5 - 0 ratings

Related issues

fubuloubu picture fubuloubu  路  3Comments

jacqueswww picture jacqueswww  路  4Comments

ben-kaufman picture ben-kaufman  路  4Comments

ben-kaufman picture ben-kaufman  路  4Comments

nrryuya picture nrryuya  路  3Comments