If one copies the code after the block: statement below into a separate file and moves it to the left, it compiles just fine, but with runnableExamples it fails
proc median*(A: var openArray[int], left, right : Natural,
myCmp : proc(x,y:int):int {.nimcall} = cmp[int]): float =
result= 1.0
runnableExamples:
static:
block:
func FCmp(x,y:float):int =
(if x==y : 0 elif x<y : -1 else: 1)
var
F = [7.0,4.0,6.0,3.0,9.0,1.0] # sorted 1 3 4 6 7 9
FSv= F
doAssert median(F,0,5,FCmp) == 1.0
#[
func FCmp below :
Error: invalid indentation [runnableExamples] failed: generated file:
## autogenerated by docgen
## loc: /home/jarausch/Nim_My/Math/BUG_X.nim(5, 1)
## rdoccmd:
import
"/home/jarausch/Nim_My/Math/BUG_X.nim"
static :
block:
func FCmp(x, y: float): int =
if x == y:
0
elif x < y: -1
else: 1
var
F = [7.0, 4.0, 6.0, 3.0, 9.0, 1.0]
FSv = F
doAssert median(F, 0, 5, FCmp) == 1.0
]#
I copy-pasted the stuff you posted, fixed wrong types in several places, and the documentation seems ok:
proc median*(A: var openArray[int], left, right: Natural,
myCmp: proc(x, y: int): int {.nimcall} = cmp[int]): float =
result = 1.0
runnableExamples:
static:
block:
func FCmp(x, y: int): int =
if x==y: 0 elif x<y: -1 else: 1
var
F = [7,4,6,3,9,1] # sorted 1 3 4 6 7 9
FSv= F
doAssert median(F,0,5,FCmp) == 1.0
I have fixed a type error myself, please see https://play.nim-lang.org/#ix=2TT2
and nim doc still get this "invalid indentation" error.
nim -v Nim Compiler Version 1.4.4 [Linux: amd64] Compiled at 2021-03-20 Copyright (c) 2006-2020 by Andreas Rumpf
active boot switches: -d:release
I have fixed a type error myself
I guess you'll have to fix your indentations and unequal whitespaces too.
I already posted the version that works. No idea why you didn't take it already and you continue to insist on your style inconsistencies which, as we can see, cause problems for the compiler.
I am sure it is a bug (or an undocumented feature)
This works fine (as in your code)
func FCmp(x,y:float):int =
if x==y: 0 elif x<y: -1 else: 1
This shows the bug
func FCmp(x,y:float):int =
(if x==y: 0 elif x<y: -1 else: 1)
This code works just fine if it is used outside of runnableExamples