[poincare/unit] Fix temperature conversion

The program would crash when trying to evaluate a unit conversion of the
form "x→_U" where U was a unit of temperature and x did not have any
unit.
This commit is contained in:
Gabriel Ozouf
2020-12-28 14:22:05 +01:00
committed by EmilieNumworks
parent 5ce5f4fbac
commit fff514d410
2 changed files with 2 additions and 1 deletions

View File

@@ -834,7 +834,7 @@ Expression Unit::ConvertTemperatureUnits(Expression e, Unit unit, ExpressionNode
Expression startUnit;
e = e.removeUnit(&startUnit);
if (startUnit.type() != ExpressionNode::Type::Unit) {
if (startUnit.isUninitialized() || startUnit.type() != ExpressionNode::Type::Unit) {
return Undefined::Builder();
}
const Representative * startRepr = static_cast<Unit &>(startUnit).representative();

View File

@@ -1267,6 +1267,7 @@ QUIZ_CASE(poincare_simplification_unit_convert) {
assert_parsed_expression_simplify_to("1→3_m", Undefined::Name());
assert_parsed_expression_simplify_to("4→_km/_m", Undefined::Name());
assert_parsed_expression_simplify_to("3×_min→_s+1-1", Undefined::Name());
assert_parsed_expression_simplify_to("0→_K", Undefined::Name());
assert_parsed_expression_simplify_to("0_K→_°C", "-273.15×_°C");
assert_parsed_expression_simplify_to("0_°C→_K", "273.15×_K");