Skip to content

Commit

Permalink
fixes #4345
Browse files Browse the repository at this point in the history
  • Loading branch information
Araq committed Jul 19, 2016
1 parent 2d8572e commit d455d58
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
5 changes: 3 additions & 2 deletions compiler/ccgexprs.nim
Original file line number Diff line number Diff line change
Expand Up @@ -1568,11 +1568,12 @@ proc genSomeCast(p: BProc, e: PNode, d: var TLoc) =
[getTypeDesc(p.module, e.typ), rdCharLoc(a)], a.s)

proc genCast(p: BProc, e: PNode, d: var TLoc) =
const floatTypes = {tyFloat..tyFloat128}
const ValueTypes = {tyFloat..tyFloat128, tyTuple, tyObject,
tyArray, tyArrayConstr}
let
destt = skipTypes(e.typ, abstractRange)
srct = skipTypes(e.sons[1].typ, abstractRange)
if destt.kind in floatTypes or srct.kind in floatTypes:
if destt.kind in ValueTypes or srct.kind in ValueTypes:
# 'cast' and some float type involved? --> use a union.
inc(p.labels)
var lbl = p.labels.rope
Expand Down
8 changes: 8 additions & 0 deletions tests/ccgbugs/tuplecast.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

# bug #4345

# only needs to compile
proc f(): tuple[a, b: uint8] = (1'u8, 2'u8)

let a, b = f()
let c = cast[int](b)

0 comments on commit d455d58

Please sign in to comment.