Unsafely cast a value to a new type

ie the result share the same C variable but my have a different mcasttype NOTE: if the adaptation is useless then value is returned as it.

ENSURE: result.name == value.name

Property definitions

nitc $ AbstractCompilerVisitor :: autoadapt
	# Unsafely cast a value to a new type
	# ie the result share the same C variable but my have a different mcasttype
	# NOTE: if the adaptation is useless then `value` is returned as it.
	# ENSURE: `result.name == value.name`
	fun autoadapt(value: RuntimeVariable, mtype: MType): RuntimeVariable
	do
		mtype = self.anchor(mtype)
		var valmtype = value.mcasttype

		# CPrimitive is the best you can do
		if valmtype.is_c_primitive then
			return value
		end

		# Do nothing if useless autocast
		if valmtype.is_subtype(self.compiler.mainmodule, null, mtype) then
			return value
		end

		# Just as_not_null if the target is not nullable.
		#
		# eg `nullable PreciseType` adapted to `Object` gives precisetype.
		if valmtype isa MNullableType and valmtype.mtype.is_subtype(self.compiler.mainmodule, null, mtype) then
			mtype = valmtype.mtype
		end

		var res = new RuntimeVariable(value.name, value.mtype, mtype)
		return res
	end
src/compiler/abstract_compiler.nit:1449,2--1477,4