at operator return -1 when fails in lists and arrays; insert operators (<< and >>) changes che container if it is a variable

This commit is contained in:
2026-07-16 07:25:15 +02:00
parent 8c55f4ac4b
commit 2f616f349b
11 changed files with 105 additions and 60 deletions
+4 -1
View File
@@ -36,6 +36,7 @@ func evalAt(ctx kern.ExprContext, opTerm *scan.Term) (v any, err error) {
return
}
v = int64(-1) // default value if not found
if array.IsArray(rightValue) {
a, _ := rightValue.(*array.ArrayType)
if index := a.IndexDeepSameCmp(leftValue); index >= 0 {
@@ -45,14 +46,16 @@ func evalAt(ctx kern.ExprContext, opTerm *scan.Term) (v any, err error) {
dict, _ := rightValue.(*dict.DictType)
if k, exists := dict.FindKey(leftValue); exists {
v = k
} else {
v = nil
}
} else if list.IsLinkedList(rightValue) {
ls, _ := rightValue.(*list.LinkedList)
if index := ls.Index(leftValue); index >= 0 {
v = index
}
} else {
v = nil
err = opTerm.ErrIncompatibleTypes(leftValue, rightValue)
}
return