# Buggy code
def parse_type(
    item, location, sigs=None, custom_units=None, custom_structs=None, constants=None
):
    # Base and custom types, e.g. num
    if isinstance(item, ast.Name):
        if item.id in base_types:
            return BaseType(item.id)
        elif item.id in special_types:
            return special_types[item.id]
        elif (custom_structs is not None) and (item.id in custom_structs):
            return make_struct_type(
                item.id,
                location,
                custom_structs[item.id],
                custom_units,
                custom_structs,
                constants,
            )
        else:
            raise InvalidTypeException("Invalid base type: " + item.id, item)
    # Units, e.g. num (1/sec) or contracts
    elif isinstance(item, ast.Call):
        # Mapping type.
        if item.func.id == "map":
            if location == "memory":
                raise InvalidTypeException(
                    "No mappings allowed for in-memory types, only fixed-size arrays",
                    item,
                )
            keytype = parse_type(
                item.args[0],
                None,
                custom_units=custom_units,
                custom_structs=custom_structs,
                constants=constants,
            )
            if not isinstance(keytype, (BaseType, ByteArrayType)):
                raise InvalidTypeException(
                    "Mapping keys must be base or bytes types", item
                )
            return MappingType(
                keytype,
                parse_type(
                    item.args[1],
                    location,
                    custom_units=custom_units,
                    custom_structs=custom_structs,
                    constants=constants,
                ),
            )
        # Contract_types
        if item.func.id == "address":
            if sigs and item.args[0].id in sigs:
                return ContractType(item.args[0].id)
        # Struct types
        if (custom_structs is not None) and (item.func.id in custom_structs):
            return make_struct_type(
                item.id, location, custom_structs[item.id], custom_units, custom_structs
            )
        if not isinstance(item.func, ast.Name):
            raise InvalidTypeException("Malformed unit type:", item)
        base_type = item.func.id
        if base_type not in ("int128", "uint256", "decimal"):
            raise InvalidTypeException(
                "You must use int128, uint256, decimal, address, contract, \
                for variable declarations and indexed for logging topics ",
                item,
            )
        if len(item.args) == 0:
            raise InvalidTypeException("Malformed unit type", item)
        if isinstance(item.args[-1], ast.Name) and item.args[-1].id == "positional":
            positional = True
            argz = item.args[:-1]
        else:
            positional = False
            argz = item.args
        if len(argz) != 1:
            raise InvalidTypeException("Malformed unit type", item)
        unit = parse_unit(argz[0], custom_units=custom_units)
        return BaseType(base_type, unit, positional)
    # Subscripts
    elif isinstance(item, ast.Subscript):
        if "value" not in vars(item.slice):
            raise InvalidTypeException(
                "Array / ByteArray access must access a single element, not a slice",
                item,
            )
        # Fixed size lists or bytearrays, e.g. num[100]
        is_constant_val = constants.ast_is_constant(item.slice.value)
        if isinstance(item.slice.value, ast.Num) or is_constant_val:
            n_val = (
                constants.get_constant(item.slice.value.id, context=None).value
                if is_constant_val
                else item.slice.value.n
            )
            if not isinstance(n_val, int) or n_val <= 0:
                raise InvalidTypeException(
                    "Arrays / ByteArrays must have a positive integral number of elements",
                    item.slice.value,
                )
            # ByteArray
            if getattr(item.value, "id", None) == "bytes":
                return ByteArrayType(n_val)
            # List
            else:
                return ListType(
                    parse_type(
                        item.value,
                        location,
                        custom_units=custom_units,
                        custom_structs=custom_structs,
                        constants=constants,
                    ),
                    n_val,
                )
        # Mappings, e.g. num[address]
        else:
            warnings.warn(
                "Mapping definitions using subscript have deprecated (see VIP564). "
                "Use map(type1, type2) instead.",
                DeprecationWarning,
            )
            raise InvalidTypeException("Unknown list type.", item)

    # Dicts, used to represent mappings, e.g. {uint: uint}. Key must be a base type
    elif isinstance(item, ast.Dict):
        warnings.warn(
            "Anonymous structs have been removed in favor of named structs, see VIP300",
            DeprecationWarning,
        )
        raise InvalidTypeException("Invalid type: %r" % ast.dump(item), item)
    elif isinstance(item, ast.Tuple):
        members = [
            parse_type(
                x,
                location,
                custom_units=custom_units,
                custom_structs=custom_structs,
                constants=constants,
            )
            for x in item.elts
        ]
        return TupleType(members)
    else:
        raise InvalidTypeException("Invalid type: %r" % ast.dump(item), item)


# Traceback (IndexError)
Error compiling:  10.txt
Traceback (most recent call last):
File "/Users/mate/ethermat/security/vyper-fuzz/venv/bin/vyper", line 4, in <module>
__import__('pkg_resources').run_script('vyper==0.1.0b6', 'vyper')
File "/Users/mate/ethermat/security/vyper-fuzz/venv/lib/python3.6/site-packages/setuptools-39.1.0-py3.6.egg/pkg_resources/__init__.py", line 658, in run_script
File "/Users/mate/ethermat/security/vyper-fuzz/venv/lib/python3.6/site-packages/setuptools-39.1.0-py3.6.egg/pkg_resources/__init__.py", line 1445, in run_script
File "/Users/mate/ethermat/security/vyper-fuzz/venv/lib/python3.6/site-packages/vyper-0.1.0b6-py3.6.egg/EGG-INFO/scripts/vyper", line 85, in <module>
File "/Users/mate/ethermat/security/vyper-fuzz/venv/lib/python3.6/site-packages/vyper-0.1.0b6-py3.6.egg/vyper/compiler.py", line 108, in compile_codes
File "/Users/mate/ethermat/security/vyper-fuzz/venv/lib/python3.6/site-packages/vyper-0.1.0b6-py3.6.egg/EGG-INFO/scripts/vyper", line 51, in exc_handler
File "/Users/mate/ethermat/security/vyper-fuzz/venv/lib/python3.6/site-packages/vyper-0.1.0b6-py3.6.egg/vyper/compiler.py", line 105, in compile_codes
File "/Users/mate/ethermat/security/vyper-fuzz/venv/lib/python3.6/site-packages/vyper-0.1.0b6-py3.6.egg/vyper/compiler.py", line 87, in <lambda>
File "/Users/mate/ethermat/security/vyper-fuzz/venv/lib/python3.6/site-packages/vyper-0.1.0b6-py3.6.egg/vyper/compiler.py", line 8, in __compile
File "/Users/mate/ethermat/security/vyper-fuzz/venv/lib/python3.6/site-packages/vyper-0.1.0b6-py3.6.egg/vyper/parser/parser.py", line 229, in parse_tree_to_lll
File "/Users/mate/ethermat/security/vyper-fuzz/venv/lib/python3.6/site-packages/vyper-0.1.0b6-py3.6.egg/vyper/parser/global_context.py", line 75, in get_global_context
File "/Users/mate/ethermat/security/vyper-fuzz/venv/lib/python3.6/site-packages/vyper-0.1.0b6-py3.6.egg/vyper/parser/global_context.py", line 307, in add_globals_and_events
File "/Users/mate/ethermat/security/vyper-fuzz/venv/lib/python3.6/site-packages/vyper-0.1.0b6-py3.6.egg/vyper/types/types.py", line 321, in parse_type
File "/Users/mate/ethermat/security/vyper-fuzz/venv/lib/python3.6/site-packages/vyper-0.1.0b6-py3.6.egg/vyper/types/types.py", line 321, in parse_type
IndexError: list index out of range

# Fixed code
def parse_type(
    item, location, sigs=None, custom_units=None, custom_structs=None, constants=None
):
    # Base and custom types, e.g. num
    if isinstance(item, ast.Name):
        if item.id in base_types:
            return BaseType(item.id)
        elif item.id in special_types:
            return special_types[item.id]
        elif (custom_structs is not None) and (item.id in custom_structs):
            return make_struct_type(
                item.id,
                location,
                custom_structs[item.id],
                custom_units,
                custom_structs,
                constants,
            )
        else:
            raise InvalidTypeException("Invalid base type: " + item.id, item)
    # Units, e.g. num (1/sec) or contracts
    elif isinstance(item, ast.Call):
        # Mapping type.
        if item.func.id == "map":
            if location == "memory":
                raise InvalidTypeException(
                    "No mappings allowed for in-memory types, only fixed-size arrays",
                    item,
                )
            if len(item.args) != 2:
                raise InvalidTypeException(
                    "Mapping requires 2 valid positional arguments.", item
                )
            keytype = parse_type(
                item.args[0],
                None,
                custom_units=custom_units,
                custom_structs=custom_structs,
                constants=constants,
            )
            if not isinstance(keytype, (BaseType, ByteArrayType)):
                raise InvalidTypeException(
                    "Mapping keys must be base or bytes types", item
                )
            return MappingType(
                keytype,
                parse_type(
                    item.args[1],
                    location,
                    custom_units=custom_units,
                    custom_structs=custom_structs,
                    constants=constants,
                ),
            )
        # Contract_types
        if item.func.id == "address":
            if sigs and item.args[0].id in sigs:
                return ContractType(item.args[0].id)
        # Struct types
        if (custom_structs is not None) and (item.func.id in custom_structs):
            return make_struct_type(
                item.id, location, custom_structs[item.id], custom_units, custom_structs
            )
        if not isinstance(item.func, ast.Name):
            raise InvalidTypeException("Malformed unit type:", item)
        base_type = item.func.id
        if base_type not in ("int128", "uint256", "decimal"):
            raise InvalidTypeException(
                "You must use int128, uint256, decimal, address, contract, \
                for variable declarations and indexed for logging topics ",
                item,
            )
        if len(item.args) == 0:
            raise InvalidTypeException("Malformed unit type", item)
        if isinstance(item.args[-1], ast.Name) and item.args[-1].id == "positional":
            positional = True
            argz = item.args[:-1]
        else:
            positional = False
            argz = item.args
        if len(argz) != 1:
            raise InvalidTypeException("Malformed unit type", item)
        unit = parse_unit(argz[0], custom_units=custom_units)
        return BaseType(base_type, unit, positional)
    # Subscripts
    elif isinstance(item, ast.Subscript):
        if "value" not in vars(item.slice):
            raise InvalidTypeException(
                "Array / ByteArray access must access a single element, not a slice",
                item,
            )
        # Fixed size lists or bytearrays, e.g. num[100]
        is_constant_val = constants.ast_is_constant(item.slice.value)
        if isinstance(item.slice.value, ast.Num) or is_constant_val:
            n_val = (
                constants.get_constant(item.slice.value.id, context=None).value
                if is_constant_val
                else item.slice.value.n
            )
            if not isinstance(n_val, int) or n_val <= 0:
                raise InvalidTypeException(
                    "Arrays / ByteArrays must have a positive integral number of elements",
                    item.slice.value,
                )
            # ByteArray
            if getattr(item.value, "id", None) == "bytes":
                return ByteArrayType(n_val)
            # List
            else:
                return ListType(
                    parse_type(
                        item.value,
                        location,
                        custom_units=custom_units,
                        custom_structs=custom_structs,
                        constants=constants,
                    ),
                    n_val,
                )
        # Mappings, e.g. num[address]
        else:
            warnings.warn(
                "Mapping definitions using subscript have deprecated (see VIP564). "
                "Use map(type1, type2) instead.",
                DeprecationWarning,
            )
            raise InvalidTypeException("Unknown list type.", item)

    # Dicts, used to represent mappings, e.g. {uint: uint}. Key must be a base type
    elif isinstance(item, ast.Dict):
        warnings.warn(
            "Anonymous structs have been removed in favor of named structs, see VIP300",
            DeprecationWarning,
        )
        raise InvalidTypeException("Invalid type: %r" % ast.dump(item), item)
    elif isinstance(item, ast.Tuple):
        members = [
            parse_type(
                x,
                location,
                custom_units=custom_units,
                custom_structs=custom_structs,
                constants=constants,
            )
            for x in item.elts
        ]
        return TupleType(members)
    else:
        raise InvalidTypeException("Invalid type: %r" % ast.dump(item), item)