def cast(self, builder, val, fromty, toty):
        """
        Cast a value of type *fromty* to type *toty*.
        This implements implicit conversions as can happen due to the
        granularity of the Numba type system, or lax Python semantics.
        """
        if fromty is types._undef_var:
            # Special case for undefined variable
            return self.get_constant_null(toty)
        elif fromty == toty or toty == types.Any:
            return val
        try:
            impl = self._casts.find((fromty, toty))
            return impl(self, builder, fromty, toty, val)
        except errors.NumbaNotImplementedError:
            raise errors.NumbaNotImplementedError(
                "Cannot cast %s to %s: %s" % (fromty, toty, val))

        Cast a value of type *fromty* to type *toty*.
        This implements implicit conversions as can happen due to the
        granularity of the Numba type system, or lax Python semantics.
        
numba/core/base.py