vyper --version): 0.1.0b17m: 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'
Add a check if it's a MappingType, then raise (maps cannot be the target of a statement, directly)
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