You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
README states that the following Contracts example code:
import contracts
from math import sqrt, floor
procisqrt[T: SomeInteger](x: T): T {.contractual.} =
require:
x >=0
ensure:
result*result<= x
(result+1) * (result+1) > x
body:
(T)(x.toBiggestFloat().sqrt().floor().toBiggestInt())
echoisqrt(18)
echoisqrt(-8)
Fails with Error: request to generate code for .compileTime proc: isqrt adding compiletime pragma.
However, that is not true:
import contracts
from math import sqrt, floor
procisqrt[T: SomeInteger](x: T): T {.contractual, compiletime.} =
require:
x >=0
ensure:
result*result<= x
(result+1) * (result+1) > x
body:
(T)(x.toBiggestFloat().sqrt().floor().toBiggestInt())
static:
echoisqrt(18)
echoisqrt(-8)
$ nim c -r example.nim
4
stack trace: (most recent call last)
(...)/example.nim(14, 13) example
(...)/.nimble/pkgs/contracts-0.1.0/contracts/contexts/contractConds.nim(19, 36) isqrt
(...)/.nimble/pkgs/contracts-0.1.0/contracts/contexts/contractConds.nim(19, 36) Error: unhandled exception: broke 'x >= 0' promised at (...)/example(5, 6) [PreConditionError]
^ the above compile-time error is exactly what is expected from the compile-time execution of that function
The error stated in the README only arises for the following code:
import contracts
from math import sqrt, floor
procisqrt[T: SomeInteger](x: T): T {.contractual, compiletime.} =
require:
x >=0
ensure:
result*result<= x
(result+1) * (result+1) > x
body:
(T)(x.toBiggestFloat().sqrt().floor().toBiggestInt())
echoisqrt(18) # calling compiletime proc at runtime here!echoisqrt(-8) # will ALWAYS raise# `Error: request to generate code for .compileTime proc: isqrt`# even without using Contracts
...however, that code raises the very same warning with no contracts whatsoever:
$ cat example.nim
from math import sqrt, floor
proc isqrt[T: SomeInteger](x: T): T {.compiletime.} =
(T)(x.toBiggestFloat().sqrt().floor().toBiggestInt())
echo isqrt(18)
echo isqrt(-8)
$ nim c example.nim
(...)/example.nim(6, 6) Error: request to generate code for .compileTime proc: isqrt
The text was updated successfully, but these errors were encountered:
README states that the following Contracts example code:
Fails with
Error: request to generate code for .compileTime proc: isqrt
addingcompiletime
pragma.However, that is not true:
^ the above compile-time error is exactly what is expected from the compile-time execution of that function
The error stated in the README only arises for the following code:
...however, that code raises the very same warning with no contracts whatsoever:
The text was updated successfully, but these errors were encountered: