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): for _, _ in fieldPairs(default T):
inc result 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: for (j, b) in bindings:
if i == j: if i == j: return b
pat = b return dropType(T)
return true
proc grab*(typ: static typedesc; bindings: sink openArray[(int, Pattern)]): Pattern = proc grab*(typ: static typedesc; bindings: sink openArray[(int, Pattern)]): Pattern =
## Construct a `Pattern` from type `typ` that selectively captures fields. ## 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) rec.fields.setLen(fieldCount typ)
var i: int var i: int
for _, f in fieldPairs(default typ): for _, f in fieldPairs(default typ):
if not match(bindings, i, rec.fields[i]): rec.fields[i] = lookup(bindings, i, f)
rec.fields[i] = dropType(typeof f)
inc i inc i
result = rec.toPattern result = rec.toPattern
elif typ is tuple: elif typ is tuple:
@ -194,8 +192,7 @@ proc grab*(typ: static typedesc; bindings: sink openArray[(int, Pattern)]): Patt
arr.items.setLen(fieldCount typ) arr.items.setLen(fieldCount typ)
var i: int var i: int
for _, f in fieldPairs(default typ): for _, f in fieldPairs(default typ):
if not match(bindings, i, arr.items[i]): arr.items[i] = lookup(bindings, i, f)
arr.items[i] = dropType(typeof f)
inc i inc i
result = arr.toPattern result = arr.toPattern
else: else:

View File

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