fixes #10456,#12928 issues when chaining templates to sortedByIt (#15734)
* update c_malloc's to csize_t fix for broken --os:ios * I'm an idiot sorry * Create talgorithm.nim * workaround for #10456 I don't understand the intricacies of how lambdalifting and template expansions interact with lent, so i don't know how to fix the real problem, but this sidesteps whatever issue that is. * working test, use typeof rather than auto
This commit is contained in:
parent
12143d90c8
commit
218acfe367
2 changed files with 19 additions and 1 deletions
|
|
@ -501,7 +501,7 @@ template sortedByIt*(seq1, op: untyped): untyped =
|
||||||
# Nested sort
|
# Nested sort
|
||||||
assert people.sortedByIt((it.age, it.name)) == @[(name: "p2", age: 20),
|
assert people.sortedByIt((it.age, it.name)) == @[(name: "p2", age: 20),
|
||||||
(name: "p3", age: 30), (name: "p4", age: 30), (name: "p1", age: 60)]
|
(name: "p3", age: 30), (name: "p4", age: 30), (name: "p1", age: 60)]
|
||||||
var result = sorted(seq1, proc(x, y: typeof(seq1[0])): int =
|
var result = sorted(seq1, proc(x, y: typeof(items(seq1), typeOfIter)): int =
|
||||||
var it {.inject.} = x
|
var it {.inject.} = x
|
||||||
let a = op
|
let a = op
|
||||||
it = y
|
it = y
|
||||||
|
|
|
||||||
18
tests/stdlib/talgorithm.nim
Normal file
18
tests/stdlib/talgorithm.nim
Normal file
|
|
@ -0,0 +1,18 @@
|
||||||
|
discard """
|
||||||
|
output:'''@["3", "2", "1"]
|
||||||
|
'''
|
||||||
|
"""
|
||||||
|
#12928,10456
|
||||||
|
import sequtils, strutils, algorithm, json
|
||||||
|
|
||||||
|
proc test() =
|
||||||
|
try:
|
||||||
|
let info = parseJson("""
|
||||||
|
{"a": ["1", "2", "3"]}
|
||||||
|
""")
|
||||||
|
let prefixes = info["a"].getElems().mapIt(it.getStr()).sortedByIt(it).reversed()
|
||||||
|
echo prefixes
|
||||||
|
except:
|
||||||
|
discard
|
||||||
|
|
||||||
|
test()
|
||||||
Loading…
Add table
Add a link
Reference in a new issue