fix #16474 unittest.check type1 is type2 gives CT error (#16476)

* fix #16474
* more tests
This commit is contained in:
flywind 2020-12-27 02:16:53 -06:00 • committed by GitHub
commit 1d615dfda7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 1 deletions

View file

@ -669,7 +669,8 @@ macro check*(conditions: untyped): untyped =
let paramAst = exp[i] let paramAst = exp[i]
if exp[i].kind == nnkIdent: if exp[i].kind == nnkIdent:
result.printOuts.add getAst(print(argStr, paramAst)) result.printOuts.add getAst(print(argStr, paramAst))
if exp[i].kind in nnkCallKinds + {nnkDotExpr, nnkBracketExpr, nnkPar}: if exp[i].kind in nnkCallKinds + {nnkDotExpr, nnkBracketExpr, nnkPar} and
(exp[i].typeKind notin {ntyTypeDesc} or $exp[0] notin ["is", "isnot"]):
let callVar = newIdentNode(":c" & $counter) let callVar = newIdentNode(":c" & $counter)
result.assigns.add getAst(asgn(callVar, paramAst)) result.assigns.add getAst(asgn(callVar, paramAst))
result.check[i] = callVar result.check[i] = callVar

View file

@ -0,0 +1,19 @@
discard """
targets: "c js"
"""
import unittest
block:
check (type(1.0)) is float
check type(1.0) is float
check (typeof(1)) isnot float
check typeof(1) isnot float
check 1.0 is float
check 1 isnot float
type T = type(0.1)
check T is float
check T isnot int