# Buggy code
def base_type_conversion(orig, frm, to, pos):
    orig = unwrap_location(orig)
    if (
        getattr(frm, "is_literal", False)
        and frm.typ in ("int128", "uint256")
        and not SizeLimits.in_bounds(frm.typ, orig.value)
    ):
        raise InvalidLiteralException("Number out of range: " + str(orig.value), pos)
    if not isinstance(frm, (BaseType, NullType)) or not isinstance(to, BaseType):
        raise TypeMismatchException(
            "Base type conversion from or to non-base type: %r %r" % (frm, to), pos
        )
    elif is_base_type(frm, to.typ) and are_units_compatible(frm, to):
        return LLLnode(
            orig.value, orig.args, typ=to, add_gas_estimate=orig.add_gas_estimate
        )
    elif (
        is_base_type(frm, "int128")
        and is_base_type(to, "decimal")
        and are_units_compatible(frm, to)
    ):
        return LLLnode.from_list(
            ["mul", orig, DECIMAL_DIVISOR],
            typ=BaseType("decimal", to.unit, to.positional),
        )
    elif isinstance(frm, NullType):
        if to.typ not in ("int128", "bool", "uint256", "address", "bytes32", "decimal"):
            # This is only to future proof the use of  base_type_conversion.
            raise TypeMismatchException(
                "Cannot convert null-type object to type %r" % to, pos
            )  # pragma: no cover
        return LLLnode.from_list(0, typ=to)
    elif isinstance(to, ContractType) and frm.typ == "address":
        return LLLnode(
            orig.value, orig.args, typ=to, add_gas_estimate=orig.add_gas_estimate
        )
    # Integer literal conversion.
    elif (frm.typ, to.typ, frm.is_literal) == ("int128", "uint256", True):
        return LLLnode(
            orig.value, orig.args, typ=to, add_gas_estimate=orig.add_gas_estimate
        )
    else:
        raise TypeMismatchException(
            "Typecasting from base type %r to %r unavailable" % (frm, to), pos
        )


# 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 base_type_conversion(orig, frm, to, pos):
    orig = unwrap_location(orig)
    if (
        getattr(frm, "is_literal", False)
        and frm.typ in ("int128", "uint256")
        and not SizeLimits.in_bounds(frm.typ, orig.value)
    ):
        raise InvalidLiteralException("Number out of range: " + str(orig.value), pos)
    # # Valid bytes[32] to bytes32 assignment.
    # if isinstance(to, BaseType) and to.typ = 'bytes32' and isinstance(frm, ByteArrayType) and frm.maxlen == 32:
    #     return LLLnode(orig.value, orig.args, typ=to, add_gas_estimate=orig.add_gas_estimate)
    if not isinstance(frm, (BaseType, NullType)) or not isinstance(to, BaseType):
        raise TypeMismatchException(
            "Base type conversion from or to non-base type: %r %r" % (frm, to), pos
        )
    elif is_base_type(frm, to.typ) and are_units_compatible(frm, to):
        return LLLnode(
            orig.value, orig.args, typ=to, add_gas_estimate=orig.add_gas_estimate
        )
    elif (
        is_base_type(frm, "int128")
        and is_base_type(to, "decimal")
        and are_units_compatible(frm, to)
    ):
        return LLLnode.from_list(
            ["mul", orig, DECIMAL_DIVISOR],
            typ=BaseType("decimal", to.unit, to.positional),
        )
    elif isinstance(frm, NullType):
        if to.typ not in ("int128", "bool", "uint256", "address", "bytes32", "decimal"):
            # This is only to future proof the use of  base_type_conversion.
            raise TypeMismatchException(
                "Cannot convert null-type object to type %r" % to, pos
            )  # pragma: no cover
        return LLLnode.from_list(0, typ=to)
    elif isinstance(to, ContractType) and frm.typ == "address":
        return LLLnode(
            orig.value, orig.args, typ=to, add_gas_estimate=orig.add_gas_estimate
        )
    # Integer literal conversion.
    elif (frm.typ, to.typ, frm.is_literal) == ("int128", "uint256", True):
        return LLLnode(
            orig.value, orig.args, typ=to, add_gas_estimate=orig.add_gas_estimate
        )
    else:
        raise TypeMismatchException(
            "Typecasting from base type %r to %r unavailable" % (frm, to), pos
        )