patterns: fix a regression in field injection
This commit is contained in:
parent
35670b2727
commit
dcd6bfe99b
|
@ -170,11 +170,10 @@ proc fieldCount(T: typedesc): int =
|
|||
for _, _ in fieldPairs(default T):
|
||||
inc result
|
||||
|
||||
proc match(bindings: sink openArray[(int, Pattern)]; i: int; pat: var Pattern): bool =
|
||||
proc lookup[T](bindings: openArray[(int, Pattern)]; i: int; _: T): Pattern =
|
||||
for (j, b) in bindings:
|
||||
if i == j:
|
||||
pat = b
|
||||
return true
|
||||
if i == j: return b
|
||||
return dropType(T)
|
||||
|
||||
proc grab*(typ: static typedesc; bindings: sink openArray[(int, Pattern)]): Pattern =
|
||||
## Construct a `Pattern` from type `typ` that selectively captures fields.
|
||||
|
@ -185,8 +184,7 @@ proc grab*(typ: static typedesc; bindings: sink openArray[(int, Pattern)]): Patt
|
|||
rec.fields.setLen(fieldCount typ)
|
||||
var i: int
|
||||
for _, f in fieldPairs(default typ):
|
||||
if not match(bindings, i, rec.fields[i]):
|
||||
rec.fields[i] = dropType(typeof f)
|
||||
rec.fields[i] = lookup(bindings, i, f)
|
||||
inc i
|
||||
result = rec.toPattern
|
||||
elif typ is tuple:
|
||||
|
@ -194,8 +192,7 @@ proc grab*(typ: static typedesc; bindings: sink openArray[(int, Pattern)]): Patt
|
|||
arr.items.setLen(fieldCount typ)
|
||||
var i: int
|
||||
for _, f in fieldPairs(default typ):
|
||||
if not match(bindings, i, arr.items[i]):
|
||||
arr.items[i] = dropType(typeof f)
|
||||
arr.items[i] = lookup(bindings, i, f)
|
||||
inc i
|
||||
result = arr.toPattern
|
||||
else:
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
# Package
|
||||
|
||||
version = "20230816"
|
||||
version = "20230822"
|
||||
author = "Emery Hemingway"
|
||||
description = "Syndicated actors for conversational concurrency"
|
||||
license = "Unlicense"
|
||||
|
|
Loading…
Reference in New Issue