private Variable replaceVariable(Function fromFunc, Variable fromVar, Function toFunc) {
		if (fromVar instanceof Parameter) {
			throw new IllegalArgumentException("replaceVariable should not be used for parameters");
		}
		Program toPgm = toFunc.getProgram();
		Program fromPgm = fromFunc.getProgram();
		String name = fromVar.getName();
		SourceType source = fromVar.getSource();
		Variable toVar = DiffUtility.getVariable(fromVar, toFunc); // requires matching storage and first-use
		if (toVar == null) {
			try {
				VariableUtilities.checkVariableConflict(toFunc, fromVar,
					fromVar.getVariableStorage(), true);
			}
			catch (VariableSizeException e) {
				throw new RuntimeException("Unexpected Exception", e);
			}
		}
		else if (toVar.equals(fromVar)) {
			return toVar;
		}
		if (fromVar.getSource() != SourceType.DEFAULT &&
			(toVar == null || !toVar.getName().equals(fromVar.getName()))) {
			if (!resolveLocalNameConflict(toFunc, fromVar.getName())) {
				return null; // Error case
			}
		}
		try {
//			if (toVar != null && !DiffUtility.variableStorageMatches(fromVar, toVar)) {
//				// if variable size does not match - play it safe and don't try to fix-up toVar
//				toVar.getFunction().removeVariable(toVar);
//				toVar = null;
//			}
			if (toVar != null) {
				// update existing variable - preserve symbol ID
				toVar.setComment(fromVar.getComment());
				DataType fromDt = fromVar.getDataType();
				if (!fromDt.isEquivalent(toVar.getDataType())) {
					toVar.setDataType(fromDt, fromVar.getVariableStorage(), true,
						fromFunc.getSignatureSource());
				}
				toVar.setName(name, source);
			}
			else {
				toVar = DiffUtility.createVariable(fromPgm, fromVar, toPgm);
			}
		}
		catch (InvalidInputException e) {
			Msg.error(this, "Unexpected Exception: " + e.getMessage(), e);
			errorMsg.append("Can't replace variable " + fromVar.getSymbol().getName(true) + "\n");
			errorMsg.append(e.getMessage() + "\n");
			return null;
		}
		catch (DuplicateNameException e) {
			Msg.error(this, "Unexpected Exception: " + e.getMessage(), e);
			errorMsg.append("Can't replace variable " + fromVar.getSymbol().getName(true) + "\n");
			errorMsg.append(e.getMessage() + "\n");
			return null;
		}
		return toVar;
	}
Replaces the local symbols in toFunc with the local symbols that are in the fromFunc.
@param toFunc the function having its local variables replaced.
@param fromFunc the source of the replacement variables.
@throws CancelledException if user cancels via the monitor.
Ghidra/Features/Base/src/main/java/ghidra/program/util/ProgramMerge.java