Skip to content

Commit

Permalink
continue fixing #13744
Browse files Browse the repository at this point in the history
  • Loading branch information
cooldome committed Mar 25, 2020
1 parent 182d3c1 commit 0597ed5
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
4 changes: 3 additions & 1 deletion compiler/semexprs.nim
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,9 @@ proc checkConvertible(c: PContext, targetTyp: PType, src: PNode): TConvStatus =
result = checkConversionBetweenObjects(d.skipTypes(abstractInst), s.skipTypes(abstractInst), pointers)
elif (targetBaseTyp.kind in IntegralTypes) and
(srcBaseTyp.kind in IntegralTypes):
if targetTyp.isOrdinalType:
if targetTyp.kind == tyBool:
discard # convOk
elif targetTyp.isOrdinalType:
if src.kind in nkCharLit..nkUInt64Lit and
src.getInt notin firstOrd(c.config, targetTyp)..lastOrd(c.config, targetTyp):
result = convNotInRange
Expand Down
9 changes: 9 additions & 0 deletions compiler/semfold.nim
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,15 @@ proc foldConv(n, a: PNode; g: ModuleGraph; check = false): PNode =
# echo high(int64)
# writeStackTrace()
case dstTyp.kind
of tyBool:
case srcTyp.kind
of tyFloat..tyFloat64:
result = newIntNodeT(int(getFloat(a) != 0.0), n, g)
of tyChar, tyUInt..tyUInt64, tyInt..tyInt64:
result = newIntNodeT(int(a.getOrdValue != 0), n, g)
else:
result = a
result.typ = n.typ
of tyInt..tyInt64, tyUInt..tyUInt64:
case srcTyp.kind
of tyFloat..tyFloat64:
Expand Down
4 changes: 3 additions & 1 deletion tests/types/tcast1.nim
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,6 @@ proc test_conv_to_bool =

static:
test_conv_to_bool()
test_conv_to_bool()
test_conv_to_bool()
const x1 = bool(-1)
let x2 = bool(2)

0 comments on commit 0597ed5

Please sign in to comment.