# Buggy code
def _check_valid_assign(self, sub):
    if isinstance(self.stmt.annotation, ast.Call):  # unit style: num(wei)
        if self.stmt.annotation.func.id != sub.typ.typ and not sub.typ.is_literal:
            raise TypeMismatchException(
                "Invalid type, expected: %s" % self.stmt.annotation.func.id, self.stmt
            )
    elif isinstance(self.stmt.annotation, ast.Dict):
        if not isinstance(sub.typ, StructType):
            raise TypeMismatchException("Invalid type, expected a struct")
    elif isinstance(self.stmt.annotation, ast.Subscript):
        if not isinstance(sub.typ, (ListType, ByteArrayType)):  # check list assign.
            raise TypeMismatchException(
                "Invalid type, expected: %s" % self.stmt.annotation.value.id, self.stmt
            )
    # Check that the integer literal, can be assigned to uint256 if necessary.
    elif (self.stmt.annotation.id, sub.typ.typ) == (
        "uint256",
        "int128",
    ) and sub.typ.is_literal:
        if not SizeLimits.in_bounds("uint256", sub.value):
            raise InvalidLiteralException(
                "Invalid uint256 assignment, value not in uint256 range.", self.stmt
            )
    elif self.stmt.annotation.id != sub.typ.typ and not sub.typ.unit:
        raise TypeMismatchException(
            "Invalid type, expected: %s" % self.stmt.annotation.id, self.stmt
        )


# Traceback (AttributeError)
----------------------------------------
Exception happened during processing of request from ('127.0.0.1', 51879)
Traceback (most recent call last):
File "/usr/local/Cellar/python/3.7.0/Frameworks/Python.framework/Versions/3.7/lib/python3.7/socketserver.py", line 647, in process_request_thread
self.finish_request(request, client_address)
File "/usr/local/Cellar/python/3.7.0/Frameworks/Python.framework/Versions/3.7/lib/python3.7/socketserver.py", line 357, in finish_request
self.RequestHandlerClass(request, client_address, self)
File "/usr/local/Cellar/python/3.7.0/Frameworks/Python.framework/Versions/3.7/lib/python3.7/socketserver.py", line 717, in __init__
self.handle()
File "/usr/local/Cellar/python/3.7.0/Frameworks/Python.framework/Versions/3.7/lib/python3.7/http/server.py", line 426, in handle
self.handle_one_request()
File "/usr/local/Cellar/python/3.7.0/Frameworks/Python.framework/Versions/3.7/lib/python3.7/http/server.py", line 414, in handle_one_request
method()
File "/Users/ryuya.nakamura/work/vyper/venv/lib/python3.7/site-packages/vyper-0.1.0b4-py3.7.egg/EGG-INFO/scripts/vyper-serve", line 66, in do_POST
File "/Users/ryuya.nakamura/work/vyper/venv/lib/python3.7/site-packages/vyper-0.1.0b4-py3.7.egg/EGG-INFO/scripts/vyper-serve", line 89, in _compile
File "/Users/ryuya.nakamura/work/vyper/venv/lib/python3.7/site-packages/vyper-0.1.0b4-py3.7.egg/vyper/compiler.py", line 44, in mk_full_signature
File "/Users/ryuya.nakamura/work/vyper/venv/lib/python3.7/site-packages/vyper-0.1.0b4-py3.7.egg/vyper/compiler.py", line 27, in gas_estimate
File "/Users/ryuya.nakamura/work/vyper/venv/lib/python3.7/site-packages/vyper-0.1.0b4-py3.7.egg/vyper/parser/parser.py", line 794, in parse_to_lll
File "/Users/ryuya.nakamura/work/vyper/venv/lib/python3.7/site-packages/vyper-0.1.0b4-py3.7.egg/vyper/parser/parser.py", line 224, in parse_tree_to_lll
File "/Users/ryuya.nakamura/work/vyper/venv/lib/python3.7/site-packages/vyper-0.1.0b4-py3.7.egg/vyper/parser/parser.py", line 172, in parse_other_functions
File "/Users/ryuya.nakamura/work/vyper/venv/lib/python3.7/site-packages/vyper-0.1.0b4-py3.7.egg/vyper/parser/parser.py", line 530, in parse_func
File "/Users/ryuya.nakamura/work/vyper/venv/lib/python3.7/site-packages/vyper-0.1.0b4-py3.7.egg/vyper/parser/parser.py", line 530, in <listcomp>
File "/Users/ryuya.nakamura/work/vyper/venv/lib/python3.7/site-packages/vyper-0.1.0b4-py3.7.egg/vyper/parser/parser.py", line 547, in parse_body
File "/Users/ryuya.nakamura/work/vyper/venv/lib/python3.7/site-packages/vyper-0.1.0b4-py3.7.egg/vyper/parser/parser.py", line 601, in parse_stmt
File "/Users/ryuya.nakamura/work/vyper/venv/lib/python3.7/site-packages/vyper-0.1.0b4-py3.7.egg/vyper/parser/stmt.py", line 76, in __init__
File "/Users/ryuya.nakamura/work/vyper/venv/lib/python3.7/site-packages/vyper-0.1.0b4-py3.7.egg/vyper/parser/stmt.py", line 150, in ann_assign
File "/Users/ryuya.nakamura/work/vyper/venv/lib/python3.7/site-packages/vyper-0.1.0b4-py3.7.egg/vyper/parser/stmt.py", line 105, in _check_valid_assign
AttributeError: 'ByteArrayType' object has no attribute 'typ'
----------------------------------------

# Fixed code
def _check_valid_assign(self, sub):
    if isinstance(self.stmt.annotation, ast.Call):  # unit style: num(wei)
        if self.stmt.annotation.func.id != sub.typ.typ and not sub.typ.is_literal:
            raise TypeMismatchException(
                "Invalid type, expected: %s" % self.stmt.annotation.func.id, self.stmt
            )
    elif (
        isinstance(self.stmt.annotation, ast.Name)
        and self.stmt.annotation.id == "bytes32"
    ):
        if isinstance(sub.typ, ByteArrayType):
            if sub.typ.maxlen != 32:
                raise TypeMismatchException(
                    "Invalid type, expected: bytes32. String is incorrect length.",
                    self.stmt,
                )
            return
        elif isinstance(sub.typ, BaseType):
            if sub.typ.typ != "bytes32":
                raise TypeMismatchException(
                    "Invalid type, expected: bytes32", self.stmt
                )
            return
        else:
            raise TypeMismatchException("Invalid type, expected: bytes32", self.stmt)
    elif isinstance(self.stmt.annotation, ast.Dict):
        if not isinstance(sub.typ, StructType):
            raise TypeMismatchException("Invalid type, expected a struct")
    elif isinstance(self.stmt.annotation, ast.Subscript):
        if not isinstance(sub.typ, (ListType, ByteArrayType)):  # check list assign.
            raise TypeMismatchException(
                "Invalid type, expected: %s" % self.stmt.annotation.value.id, self.stmt
            )
    # Check that the integer literal, can be assigned to uint256 if necessary.
    elif (self.stmt.annotation.id, sub.typ.typ) == (
        "uint256",
        "int128",
    ) and sub.typ.is_literal:
        if not SizeLimits.in_bounds("uint256", sub.value):
            raise InvalidLiteralException(
                "Invalid uint256 assignment, value not in uint256 range.", self.stmt
            )
    elif self.stmt.annotation.id != sub.typ.typ and not sub.typ.unit:
        raise TypeMismatchException(
            "Invalid type, expected: %s" % self.stmt.annotation.id, self.stmt
        )