summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--compiler/cgen.nim10
-rw-r--r--lib/system/indices.nim5
2 files changed, 10 insertions, 5 deletions
diff --git a/compiler/cgen.nim b/compiler/cgen.nim
index a52d41999..287a6f5e4 100644
--- a/compiler/cgen.nim
+++ b/compiler/cgen.nim
@@ -1070,7 +1070,11 @@ proc allPathsAsgnResult(p: BProc; n: PNode): InitResultEnum =
       if result != Unknown: return result
   of nkAsgn, nkFastAsgn, nkSinkAsgn:
     if n[0].kind == nkSym and n[0].sym.kind == skResult:
-      if not containsResult(n[1]): result = InitSkippable
+      if not containsResult(n[1]):
+        if allPathsAsgnResult(p, n[1]) == InitRequired:
+          result = InitRequired
+        else:
+          result = InitSkippable
       else: result = InitRequired
     elif containsResult(n):
       result = InitRequired
@@ -1148,6 +1152,10 @@ proc allPathsAsgnResult(p: BProc; n: PNode): InitResultEnum =
         allPathsInBranch(n[i])
   of nkRaiseStmt:
     result = InitRequired
+  of nkChckRangeF, nkChckRange64, nkChckRange:
+    # TODO: more checks might need to be covered like overflow, indexDefect etc.
+    # bug #22852
+    result = InitRequired
   else:
     for i in 0..<n.safeLen:
       allPathsInBranch(n[i])
diff --git a/lib/system/indices.nim b/lib/system/indices.nim
index e1ac68383..8f0acb931 100644
--- a/lib/system/indices.nim
+++ b/lib/system/indices.nim
@@ -114,11 +114,8 @@ proc `[]`*[Idx, T; U, V: Ordinal](a: array[Idx, T], x: HSlice[U, V]): seq[T] {.s
   ##   ```
   let xa = a ^^ x.a
   let L = (a ^^ x.b) - xa + 1
-  # Workaround bug #22852:
-  result = newSeq[T](if L < 0: 0 else: L)
+  result = newSeq[T](L)
   for i in 0..<L: result[i] = a[Idx(i + xa)]
-  # Workaround bug #22852
-  discard Natural(L)
 
 proc `[]=`*[Idx, T; U, V: Ordinal](a: var array[Idx, T], x: HSlice[U, V], b: openArray[T]) {.systemRaisesDefect.} =
   ## Slice assignment for arrays.