-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
document #15618 #15810
document #15618 #15810
Conversation
Can we fix it instead? |
I think we should make this work to fix this issue. var x = 4
doAssert 4.0 == x |
no, this can't work. |
var x = 2 + 2 # maybe have side effects
doAsssert 4.0 == x
checkpointes(... & $x) And func double*(n: float): float = n * 2
doAssert(double(-2) == -4)
test "double -2": check(double(-2) == -4) is converted to: func double*(n: float): float = n * 2
var x = double(-2) # maybe have side effects
doAssert(x == -4)
checkpointes(... & $x) |
check lhs == rhs note that in future work |
Thanks for hints! I will give a try. But how about this? import unittest
check 2.0 + 2.0 == 2 + 2 # works with doAssert
check 2 + 2 == 2.0 + 2.0 # works with doAssert
var x: int = 2.0 + 2.0 # This failed. or lhs and rhs are both functions. It may not be hard. But I think It is error-prone. |
here's a working prototype: when true:
import macros
macro commonType(a, b: typed): untyped =
if a.kind == nnkIntLit:
result = quote do:
type(`b`)
else:
result = quote do:
type(`a`)
macro check2(cond: untyped): untyped =
let op=cond[0]
let a1=cond[1]
let a2=cond[2]
let s = cond.repr.newLit
result = quote do:
type T = commonType(`a1`, `a2`)
let lhs: T = `a1`
let rhs: T = `a2`
if not(`op`(lhs, rhs)):
doAssert false, $(lhs, rhs, `s`)
check2(2+2 == 2.0 + 2.0)
check2(2.0 + 2.0 == 2+2)
check2(2+3 == 2.0 + 2.0) # this will show the errmsg |
Co-authored-by: Juan Carlos <juancarlospaco@gmail.com>
* document #15618 * Update lib/pure/unittest.nim * Update lib/pure/unittest.nim Co-authored-by: Juan Carlos <juancarlospaco@gmail.com> * Update lib/pure/unittest.nim Co-authored-by: Andreas Rumpf <rumpf_a@web.de> Co-authored-by: Juan Carlos <juancarlospaco@gmail.com> (cherry picked from commit adde5ba)
* document nim-lang#15618 * Update lib/pure/unittest.nim * Update lib/pure/unittest.nim Co-authored-by: Juan Carlos <juancarlospaco@gmail.com> * Update lib/pure/unittest.nim Co-authored-by: Andreas Rumpf <rumpf_a@web.de> Co-authored-by: Juan Carlos <juancarlospaco@gmail.com>
* document nim-lang#15618 * Update lib/pure/unittest.nim * Update lib/pure/unittest.nim Co-authored-by: Juan Carlos <juancarlospaco@gmail.com> * Update lib/pure/unittest.nim Co-authored-by: Andreas Rumpf <rumpf_a@web.de> Co-authored-by: Juan Carlos <juancarlospaco@gmail.com>
* document nim-lang#15618 * Update lib/pure/unittest.nim * Update lib/pure/unittest.nim Co-authored-by: Juan Carlos <juancarlospaco@gmail.com> * Update lib/pure/unittest.nim Co-authored-by: Andreas Rumpf <rumpf_a@web.de> Co-authored-by: Juan Carlos <juancarlospaco@gmail.com>
* document nim-lang#15618 * Update lib/pure/unittest.nim * Update lib/pure/unittest.nim Co-authored-by: Juan Carlos <juancarlospaco@gmail.com> * Update lib/pure/unittest.nim Co-authored-by: Andreas Rumpf <rumpf_a@web.de> Co-authored-by: Juan Carlos <juancarlospaco@gmail.com>
No description provided.