Skip to content

Commit 5bf0568

Browse files
committed
Improve AssociateTo error message
1 parent 031aed6 commit 5bf0568

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/builtin/AssociationFunctions.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,9 @@ public IExpr apply(final IExpr symbolValue) {
140140
return IOFunctions.printMessage(S.AssociateTo, "invdt", F.List(), EvalEngine.get());
141141
}
142142
}
143-
return F.NIL;
143+
// The argument `1` is not a valid Association.
144+
return IOFunctions.printMessage(
145+
S.AssociateTo, "invak", F.List(symbolValue), EvalEngine.get());
144146
}
145147
}
146148

@@ -185,7 +187,8 @@ private static IExpr assignPartTo(
185187
return symbol.assignedValue();
186188
}
187189
// The argument `1` is not a valid Association.
188-
return IOFunctions.printMessage(ast.topHead(), "invak", F.List(oldValue), EvalEngine.get());
190+
return IOFunctions.printMessage(
191+
ast.topHead(), "invak", F.List(oldValue), EvalEngine.get());
189192
}
190193
// The argument is not a rule or a list of rules.
191194
return IOFunctions.printMessage(ast.topHead(), "invdt", F.List(), EvalEngine.get());

symja_android_library/matheclipse-io/src/test/java/org/matheclipse/io/system/AssociationTest.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,14 @@ public AssociationTest(String name) {
1717
}
1818

1919
public void testAssociateTo() {
20+
check(
21+
"aa=42", //
22+
"42");
23+
// AssociateTo: aa is not a variable with a value, so its value cannot be changed.
24+
check(
25+
"AssociateTo(aa , c->17)", //
26+
"AssociateTo(aa,c->17)");
27+
2028
check(
2129
"assoc = <|\"A\" -> <|\"a\" -> 1, \"b\" -> 2, \"c\" -> 3|>|>", //
2230
"<|A-><|a->1,b->2,c->3|>|>");

0 commit comments

Comments
 (0)