patterns: fix a regression in field injection

This commit is contained in:
Emery Hemingway 2023-08-22 11:06:04 +01:00
parent 35670b2727
commit dcd6bfe99b
2 changed files with 6 additions and 9 deletions

View File

@ -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:

View File

@ -1,6 +1,6 @@
# Package
version = "20230816"
version = "20230822"
author = "Emery Hemingway"
description = "Syndicated actors for conversational concurrency"
license = "Unlicense"