[apps/poincare] Forbid variable creation with same name as existing func

This commit is contained in:
Léa Saviot
2018-11-07 17:40:23 +01:00
committed by Émilie Feral
parent 0670057f90
commit 8b2c00d8ba
2 changed files with 7 additions and 0 deletions

View File

@@ -102,6 +102,9 @@ const Expression GlobalContext::ExpressionForActualSymbol(const SymbolAbstract &
}
Ion::Storage::Record::ErrorStatus GlobalContext::SetExpressionForActualSymbol(const Expression & expression, const SymbolAbstract & symbol, Ion::Storage::Record previousRecord) {
if (!previousRecord.isNull() && Ion::Storage::FullNameHasExtension(previousRecord.fullName(), funcExtension, strlen(funcExtension))) {
return Ion::Storage::Record::ErrorStatus::NameTaken;
}
// Delete any record with same name (as it is going to be overriden)
previousRecord.destroy();
return Ion::Storage::sharedStorage()->createRecordWithExtension(symbol.name(), expExtension, expression.addressInPool(), expression.size());

View File

@@ -5,6 +5,7 @@
#include <poincare/horizontal_layout.h>
#include <poincare/serialization_helper.h>
#include <poincare/symbol.h>
#include <poincare/undefined.h>
#include <ion.h>
extern "C" {
#include <assert.h>
@@ -67,6 +68,9 @@ Expression Store::shallowReduce(Context & context, Preferences::AngleUnit angleU
}
context.setExpressionForSymbol(finalValue.simplify(context, angleUnit, false), symbol(), context);
Expression e = context.expressionForSymbol(symbol());
if (e.isUninitialized()) {
return Undefined();
}
replaceWithInPlace(e);
return e.shallowReduce(context, angleUnit, replaceSymbols);
}