From d455d58af6c511414f59eff2fffd64379dd4deac Mon Sep 17 00:00:00 2001 From: Andreas Rumpf Date: Tue, 19 Jul 2016 15:40:21 +0200 Subject: [PATCH] fixes #4345 --- compiler/ccgexprs.nim | 5 +++-- tests/ccgbugs/tuplecast.nim | 8 ++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) create mode 100644 tests/ccgbugs/tuplecast.nim diff --git a/compiler/ccgexprs.nim b/compiler/ccgexprs.nim index c47478b9cd..3f12fed2ce 100644 --- a/compiler/ccgexprs.nim +++ b/compiler/ccgexprs.nim @@ -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 diff --git a/tests/ccgbugs/tuplecast.nim b/tests/ccgbugs/tuplecast.nim new file mode 100644 index 0000000000..d60e8c4902 --- /dev/null +++ b/tests/ccgbugs/tuplecast.nim @@ -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)