Return whether source ir type is implicitly castable to target

    Based on the underlying datatypes and the value in case of Literals
516000
def castable(source, target):
    
    op = source.op()
    value = getattr(op, 'value', None)
    return dt.castable(source.type(), target.type(), value=value)
1324727
def _safe_cast(out_type, val):
    
    if val is None:
        return None

    if out_type == int:
        if isinstance(val, int) or isinstance(val, float):
            # Just a number.
            return int(val)
        else:
            # Process any other type as a string.
            if isinstance(val, bytes):
                val = val.decode('utf-8', 'ignore')
            elif not isinstance(val, six.string_types):
                val = six.text_type(val)
            # Get a number from the front of the string.
            match = re.match(r'[\+-]?[0-9]+', val.strip())
            return int(match.group(0)) if match else 0

    elif out_type == bool:
        try:
            # Should work for strings, bools, ints:
            return bool(int(val))
        except ValueError:
            return False

    elif out_type == six.text_type:
        if isinstance(val, bytes):
            return val.decode('utf-8', 'ignore')
        elif isinstance(val, six.text_type):
            return val
        else:
            return six.text_type(val)

    elif out_type == float:
        if isinstance(val, int) or isinstance(val, float):
            return float(val)
        else:
            if isinstance(val, bytes):
                val = val.decode('utf-8', 'ignore')
            else:
                val = six.text_type(val)
            match = re.match(r'[\+-]?([0-9]+\.?[0-9]*|[0-9]*\.[0-9]+)',
                             val.strip())
            if match:
                val = match.group(0)
                if val:
                    return float(val)
            return 0.0

    else:
        return val
343001
function isReliableScope(scope: OriginalScope): boolean {
  let totalBindings = 0;
  let unknownBindings = 0;

  for (let s = scope; s; s = s.parent) {
    const vars = (s.bindings && s.bindings.variables) || {};
    for (const key of Object.keys(vars)) {
      const binding = vars[key];

      totalBindings += 1;
      if (
        binding.value &&
        typeof binding.value === "object" &&
        (binding.value.type === "unscoped" || binding.value.type === "unmapped")
      ) {
        unknownBindings += 1;
      }
    }
  }

  // As determined by fair dice roll.
  return totalBindings === 0 || unknownBindings / totalBindings < 0.25;
}
1268848
def _compile_literal(self, data):
        """"""
        if data is None:
            return 'nil'
        elif data is True:
            return 'yes'
        elif data is False:
            return 'no'
        else:
            return repr(data)
1242971
def actualize_source_type (self, sources, prop_set):
        
        assert is_iterable_typed(sources, VirtualTarget)
        assert isinstance(prop_set, property_set.PropertySet)
        result = []
        for i in sources:
            scanner = None

# FIXME: what's this?
#            if isinstance (i, str):
#                i = self.manager_.get_object (i)

            if i.type ():
                scanner = b2.build.type.get_scanner (i.type (), prop_set)

            r = i.actualize (scanner)
            result.append (r)

        return result
118215
function isTypedArrayLike( value ) {
	return (
		value !== null &&
		typeof value === 'object' &&
		isInteger( value.length ) &&
		value.length >= 0 &&
		value.length <= MAX &&
		typeof value.BYTES_PER_ELEMENT === 'number' &&
		typeof value.byteOffset === 'number' &&
		typeof value.byteLength === 'number'
	);
}
452513
@JRubyMethod
    public static IRubyObject detect_implicit(IRubyObject self, IRubyObject val) {
        IRubyObject tmp = TypeConverter.convertToTypeWithCheck(val, self.getRuntime().getString(), "to_str");
        if(!tmp.isNil()) {
            ByteList bl = ((RubyString)tmp).getByteList();
            String type_id = ImplicitScanner2.matchImplicit(Pointer.create(bl.bytes, bl.begin), bl.realSize);
            return self.getRuntime().newString(type_id);
        }
        return RubyString.newEmptyString(self.getRuntime());
    }
861542
def can_convert(strict: bool, from_type: Type[S], to_type: Type[T]):
    
    if (to_type is not None) and (to_type not in (all_primitive_types + all_np_primitive_types)):
        return False
    else:
        return True
438716
def _get_ll_pointer_type(self, target_data, context=None):
        
        from . import Module, GlobalVariable
        from ..binding import parse_assembly

        if context is None:
            m = Module()
        else:
            m = Module(context=context)
        foo = GlobalVariable(m, self, name="foo")
        with parse_assembly(str(m)) as llmod:
            return llmod.get_global_variable(foo.name).type
210755
private static Conversion<?> getTypeConversion(
			Object typeKey, Object value) {

		// Check if the provided value is already of the target type
		if (typeKey instanceof Class && ((Class)typeKey)!=Object.class
				&& ((Class)typeKey).isInstance(value)) {
			return IDENTITY_CONVERSION;
		}

		// Find the type conversion object
		return (value instanceof Convertible)
			? ((Convertible)value).getTypeConversion(typeKey)
			: typeConversions.get(typeKey);
	}
1192908
private static boolean isAssignableFrom(Type from, GenericArrayType to) {
		Type toGenericComponentType = to.getGenericComponentType();
		if (toGenericComponentType instanceof ParameterizedType) {
			Type t = from;
			if (from instanceof GenericArrayType) {
				t = ((GenericArrayType) from).getGenericComponentType();
			} else if (from instanceof Class) {
				Class<?> classType = (Class<?>) from;
				while (classType.isArray()) {
					classType = classType.getComponentType();
				}
				t = classType;
			}
			return isAssignableFrom(t,
					(ParameterizedType) toGenericComponentType,
					new HashMap<String, Type>());
		}
		// No generic defined on "to"; therefore, return true and let other
		// checks determine assignability
		return true;
	}
961912
def _cast_to_type(self, value):
        
        if not isinstance(value, list):
            self.fail('invalid', value=value)
        return value
1012238
function (source, keyS, target, keyT) {
      var desc = Object.getOwnPropertyDescriptor(source, keyS);
      if (desc) {
        desc.enumerable = false;
        target[keyT] = desc;
      }
    }
723874
function isAttrDifferent (newAttrs, oldAttrs, attributeName) {
  let oldValue = _.get(oldAttrs, attributeName + '.value')
  let newValue = _.get(newAttrs, attributeName + '.value')

  if (newValue !== undefined && !_.isEqual(oldValue, newValue)) {
    return true
  }
  return false
}
217597
def _cast_to_type(self, value):
        
        if isinstance(value, str) or value is None:
            return value
        return str(value)
978984
function inferDtype(value) {
  return (
    (value === null || isUndefined(value)) ? null :
    isNumber(value) ? 'number' :
    isBoolean(value) ? 'boolean' :
    isString(value) ? 'string' :
    isDate(value) ? 'date' :
    'object'
  );
}
1028147
private static Object castObject(
        Class<?> toType, Class<?> fromType, Object fromValue,
        int operation, boolean checkOnly )
        throws UtilEvalError
    {
        /*
            Lots of preconditions checked here...
            Once things are running smoothly we might comment these out
            (That's what assertions are for).
        */
        if ( checkOnly && fromValue != null )
            throw new InterpreterError("bad cast params 1");
        if ( !checkOnly && fromValue == null )
            throw new InterpreterError("bad cast params 2");
        if ( fromType == Primitive.class )
            throw new InterpreterError("bad from Type, need to unwrap");
        if ( fromValue == Primitive.NULL && fromType != null )
            throw new InterpreterError("inconsistent args 1");
        if ( fromValue == Primitive.VOID && fromType != Void.TYPE )
            throw new InterpreterError("inconsistent args 2");
        if ( toType == Void.TYPE )
            throw new InterpreterError("loose toType should be null");

        // assignment to loose type, void type, or exactly same type
        if ( toType == null || arrayElementType(toType) == arrayElementType(fromType) )
            return checkOnly ? VALID_CAST :
                fromValue;

        if ( null != fromType && fromType.isArray() )
            if ( operation == Types.CAST
                    || isJavaAssignable(Collection.class, toType)
                    || isJavaAssignable(Map.class, toType) )
                return checkOnly ? VALID_CAST : BshArray.castArray(
                        toType, fromType, fromValue );

        // Casting to primitive type
        if ( toType.isPrimitive() )
        {
            if ( fromType == Void.TYPE || fromType == null
                || fromType.isPrimitive() )
            {
                // Both primitives, do primitive cast
                return Primitive.castPrimitive(
                    toType, fromType, (Primitive)fromValue,
                    checkOnly, operation );
            } else
            {
                if ( Primitive.isWrapperType( fromType ) )
                {
                    // wrapper to primitive
                    // Convert value to Primitive and check/cast it.

                    //Object r = checkOnly ? VALID_CAST :
                    Class unboxedFromType = Primitive.unboxType( fromType );
                    Primitive primFromValue;
                    if ( checkOnly )
                        primFromValue = null; // must be null in checkOnly
                    else
                        primFromValue = (Primitive)Primitive.wrap(
                            fromValue, unboxedFromType );

                    return Primitive.castPrimitive(
                        toType, unboxedFromType, primFromValue,
                        checkOnly, operation );
                } else
                {
                    // Cannot cast from arbitrary object to primitive
                    if ( checkOnly )
                        return INVALID_CAST;
                    else
                        throw castError( toType, fromType, operation );
                }
            }
        }

        // Else, casting to reference type

        // Casting from primitive or void (to reference type)
        if ( fromType == Void.TYPE || fromType == null
            || fromType.isPrimitive() )
        {
            // cast from primitive to wrapper type
            if ( Primitive.isWrapperType( toType )
                && fromType != Void.TYPE && fromType != null )
            {
                // primitive to wrapper type
                return checkOnly ? VALID_CAST :
                    Primitive.castWrapper(
                        Primitive.unboxType(toType),
                        ((Primitive)fromValue).getValue() );
            }

            // Primitive (not null or void) to Object.class type
            if ( toType == Object.class
                && fromType != Void.TYPE && fromType != null )
            {
                // box it
                return checkOnly ? VALID_CAST :
                    ((Primitive)fromValue).getValue();
            }

            // Primitive to arbitrary object type.
            // Allow Primitive.castToType() to handle it as well as cases of
            // Primitive.NULL and Primitive.VOID
            return Primitive.castPrimitive(
                toType, fromType, (Primitive)fromValue, checkOnly, operation );
        }

        // If type already assignable no cast necessary
        // We do this last to allow various errors above to be caught.
        // e.g cast Primitive.Void to Object would pass this
        if ( toType.isAssignableFrom( fromType ) )
            return checkOnly ? VALID_CAST :
                fromValue;

        // Can we use the proxy mechanism to cast a bsh.This to
        // the correct interface?
        if ( toType.isInterface()
            && bsh.This.class.isAssignableFrom( fromType )
        )
            return checkOnly ? VALID_CAST :
                ((bsh.This)fromValue).getInterface( toType );

        // Both numeric wrapper types?
        // Try numeric style promotion wrapper cast
        if ( Primitive.isWrapperType( toType )
            && Primitive.isWrapperType( fromType ) )
            return checkOnly ? VALID_CAST :
                Primitive.castWrapper( toType, fromValue );

        if ( checkOnly )
            return INVALID_CAST;
        else
            throw castError( toType, fromType , operation  );
    }