* fixes #6016 union alias trigger bad codegen * cpp test ok * merging some test into one file
This commit is contained in:
parent
f063943d5f
commit
57edf619fe
6 changed files with 176 additions and 141 deletions
|
|
@ -336,6 +336,7 @@ proc getTypePre(m: BModule, typ: PType; sig: SigHash): Rope =
|
||||||
if result == nil: result = cacheGetType(m.typeCache, sig)
|
if result == nil: result = cacheGetType(m.typeCache, sig)
|
||||||
|
|
||||||
proc structOrUnion(t: PType): Rope =
|
proc structOrUnion(t: PType): Rope =
|
||||||
|
let t = t.skipTypes({tyAlias})
|
||||||
(if tfUnion in t.flags: rope("union") else: rope("struct"))
|
(if tfUnion in t.flags: rope("union") else: rope("struct"))
|
||||||
|
|
||||||
proc getForwardStructFormat(m: BModule): string =
|
proc getForwardStructFormat(m: BModule): string =
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,22 @@
|
||||||
discard """
|
discard """
|
||||||
|
output: '''100'''
|
||||||
cmd: "nim cpp $file"
|
cmd: "nim cpp $file"
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import typeinfo
|
import typeinfo
|
||||||
|
|
||||||
|
#bug #6016
|
||||||
|
type
|
||||||
|
Onion {.union.} = object
|
||||||
|
field1: int
|
||||||
|
field2: uint64
|
||||||
|
|
||||||
|
Stroom = Onion
|
||||||
|
|
||||||
|
PStroom = ptr Stroom
|
||||||
|
|
||||||
|
proc pstruct(u: PStroom) =
|
||||||
|
echo u.field2
|
||||||
|
|
||||||
|
var x = Onion(field1: 100)
|
||||||
|
pstruct(x.addr)
|
||||||
|
|
@ -1,50 +0,0 @@
|
||||||
discard """
|
|
||||||
output: '''19
|
|
||||||
(c: 0)
|
|
||||||
(c: 13)
|
|
||||||
@[(c: 11)]
|
|
||||||
@[(c: 17)]'''
|
|
||||||
"""
|
|
||||||
# bug #5238
|
|
||||||
|
|
||||||
type
|
|
||||||
Rgba8 = object
|
|
||||||
c: int
|
|
||||||
BlenderRgb*[ColorT] = object
|
|
||||||
|
|
||||||
template getColorType*[C](x: typedesc[BlenderRgb[C]]): typedesc = C
|
|
||||||
|
|
||||||
type
|
|
||||||
ColorT = getColorType(BlenderRgb[int])
|
|
||||||
|
|
||||||
proc setColor(c: var ColorT) =
|
|
||||||
c = 19
|
|
||||||
|
|
||||||
var n: ColorT
|
|
||||||
n.setColor()
|
|
||||||
echo n
|
|
||||||
|
|
||||||
type
|
|
||||||
ColorType = getColorType(BlenderRgb[Rgba8])
|
|
||||||
|
|
||||||
var x: ColorType
|
|
||||||
echo x
|
|
||||||
|
|
||||||
proc setColor(c: var ColorType) =
|
|
||||||
c = Rgba8(c: 13)
|
|
||||||
|
|
||||||
proc setColor(c: var seq[ColorType]) =
|
|
||||||
c[0] = Rgba8(c: 11)
|
|
||||||
|
|
||||||
proc setColorArray(c: var openArray[ColorType]) =
|
|
||||||
c[0] = Rgba8(c: 17)
|
|
||||||
|
|
||||||
x.setColor()
|
|
||||||
echo x
|
|
||||||
|
|
||||||
var y = @[Rgba8(c:15)]
|
|
||||||
y.setColor()
|
|
||||||
echo y
|
|
||||||
|
|
||||||
y.setColorArray()
|
|
||||||
echo y
|
|
||||||
158
tests/types/taliasbugs.nim
Normal file
158
tests/types/taliasbugs.nim
Normal file
|
|
@ -0,0 +1,158 @@
|
||||||
|
discard """
|
||||||
|
msg: '''true
|
||||||
|
true
|
||||||
|
true
|
||||||
|
true
|
||||||
|
true
|
||||||
|
true'''
|
||||||
|
output: '''true
|
||||||
|
true
|
||||||
|
true
|
||||||
|
true
|
||||||
|
true
|
||||||
|
true
|
||||||
|
R
|
||||||
|
R
|
||||||
|
R
|
||||||
|
R
|
||||||
|
19
|
||||||
|
(c: 0)
|
||||||
|
(c: 13)
|
||||||
|
@[(c: 11)]
|
||||||
|
@[(c: 17)]
|
||||||
|
100'''
|
||||||
|
"""
|
||||||
|
|
||||||
|
# bug #5360
|
||||||
|
import macros
|
||||||
|
|
||||||
|
type
|
||||||
|
Order = enum
|
||||||
|
R
|
||||||
|
OrderAlias = Order
|
||||||
|
|
||||||
|
template getOrderTypeA(): typedesc = Order
|
||||||
|
template getOrderTypeB(): typedesc = OrderAlias
|
||||||
|
|
||||||
|
type
|
||||||
|
OrderR = getOrderTypeA()
|
||||||
|
OrderG = getOrderTypeB()
|
||||||
|
|
||||||
|
macro typeRep(a, b: typed): untyped =
|
||||||
|
if sameType(a, b):
|
||||||
|
echo "true"
|
||||||
|
else:
|
||||||
|
echo "false"
|
||||||
|
|
||||||
|
template test(a, b: typedesc) =
|
||||||
|
when a is b:
|
||||||
|
echo "true"
|
||||||
|
else:
|
||||||
|
echo "false"
|
||||||
|
|
||||||
|
test(OrderAlias, Order)
|
||||||
|
test(OrderR, Order)
|
||||||
|
test(OrderG, Order)
|
||||||
|
|
||||||
|
test(OrderR, OrderG)
|
||||||
|
test(OrderR, OrderAlias)
|
||||||
|
test(OrderG, OrderAlias)
|
||||||
|
|
||||||
|
typeRep(OrderAlias.R, Order.R) # true
|
||||||
|
typeRep(OrderR.R, Order.R) # true
|
||||||
|
typeRep(OrderG.R, Order.R) # true
|
||||||
|
|
||||||
|
typeRep(OrderR.R, OrderAlias.R) # true
|
||||||
|
typeRep(OrderG.R, OrderAlias.R) # true
|
||||||
|
typeRep(OrderR.R, OrderG.R) # true
|
||||||
|
|
||||||
|
echo OrderR.R # R
|
||||||
|
echo OrderG.R # R
|
||||||
|
echo OrderAlias.R # R
|
||||||
|
echo Order.R # R
|
||||||
|
|
||||||
|
# bug #5238
|
||||||
|
|
||||||
|
type
|
||||||
|
Rgba8 = object
|
||||||
|
c: int
|
||||||
|
BlenderRgb*[ColorT] = object
|
||||||
|
|
||||||
|
template getColorType*[C](x: typedesc[BlenderRgb[C]]): typedesc = C
|
||||||
|
|
||||||
|
type
|
||||||
|
ColorT = getColorType(BlenderRgb[int])
|
||||||
|
|
||||||
|
proc setColor(c: var ColorT) =
|
||||||
|
c = 19
|
||||||
|
|
||||||
|
var n: ColorT
|
||||||
|
n.setColor()
|
||||||
|
echo n
|
||||||
|
|
||||||
|
type
|
||||||
|
ColorType = getColorType(BlenderRgb[Rgba8])
|
||||||
|
|
||||||
|
var x: ColorType
|
||||||
|
echo x
|
||||||
|
|
||||||
|
proc setColor(c: var ColorType) =
|
||||||
|
c = Rgba8(c: 13)
|
||||||
|
|
||||||
|
proc setColor(c: var seq[ColorType]) =
|
||||||
|
c[0] = Rgba8(c: 11)
|
||||||
|
|
||||||
|
proc setColorArray(c: var openArray[ColorType]) =
|
||||||
|
c[0] = Rgba8(c: 17)
|
||||||
|
|
||||||
|
x.setColor()
|
||||||
|
echo x
|
||||||
|
|
||||||
|
var y = @[Rgba8(c:15)]
|
||||||
|
y.setColor()
|
||||||
|
echo y
|
||||||
|
|
||||||
|
y.setColorArray()
|
||||||
|
echo y
|
||||||
|
|
||||||
|
#bug #6016
|
||||||
|
type
|
||||||
|
Onion {.union.} = object
|
||||||
|
field1: int
|
||||||
|
field2: uint64
|
||||||
|
|
||||||
|
Stroom = Onion
|
||||||
|
|
||||||
|
PStroom = ptr Stroom
|
||||||
|
|
||||||
|
proc pstruct(u: PStroom) =
|
||||||
|
echo u.field2
|
||||||
|
|
||||||
|
var oni = Onion(field1: 100)
|
||||||
|
pstruct(oni.addr)
|
||||||
|
|
||||||
|
|
||||||
|
# bug #4124
|
||||||
|
|
||||||
|
import sequtils
|
||||||
|
|
||||||
|
type
|
||||||
|
Foo = distinct string
|
||||||
|
|
||||||
|
var
|
||||||
|
foo: Foo
|
||||||
|
|
||||||
|
type
|
||||||
|
Alias = (type(foo))
|
||||||
|
var
|
||||||
|
a: Alias
|
||||||
|
|
||||||
|
a = foo
|
||||||
|
|
||||||
|
when true:
|
||||||
|
var xs = @[1,2,3]
|
||||||
|
|
||||||
|
proc asFoo(i: string): Foo =
|
||||||
|
Foo(i)
|
||||||
|
|
||||||
|
var xx = xs.mapIt(asFoo($(it + 5)))
|
||||||
|
|
@ -1,66 +0,0 @@
|
||||||
discard """
|
|
||||||
msg: '''true
|
|
||||||
true
|
|
||||||
true
|
|
||||||
true
|
|
||||||
true
|
|
||||||
true'''
|
|
||||||
output: '''true
|
|
||||||
true
|
|
||||||
true
|
|
||||||
true
|
|
||||||
true
|
|
||||||
true
|
|
||||||
R
|
|
||||||
R
|
|
||||||
R
|
|
||||||
R'''
|
|
||||||
"""
|
|
||||||
|
|
||||||
# bug #5360
|
|
||||||
import macros
|
|
||||||
|
|
||||||
type
|
|
||||||
Order = enum
|
|
||||||
R
|
|
||||||
OrderAlias = Order
|
|
||||||
|
|
||||||
template getOrderTypeA(): typedesc = Order
|
|
||||||
template getOrderTypeB(): typedesc = OrderAlias
|
|
||||||
|
|
||||||
type
|
|
||||||
OrderR = getOrderTypeA()
|
|
||||||
OrderG = getOrderTypeB()
|
|
||||||
|
|
||||||
macro typeRep(a, b: typed): untyped =
|
|
||||||
if sameType(a, b):
|
|
||||||
echo "true"
|
|
||||||
else:
|
|
||||||
echo "false"
|
|
||||||
|
|
||||||
template test(a, b: typedesc) =
|
|
||||||
when a is b:
|
|
||||||
echo "true"
|
|
||||||
else:
|
|
||||||
echo "false"
|
|
||||||
|
|
||||||
test(OrderAlias, Order)
|
|
||||||
test(OrderR, Order)
|
|
||||||
test(OrderG, Order)
|
|
||||||
|
|
||||||
test(OrderR, OrderG)
|
|
||||||
test(OrderR, OrderAlias)
|
|
||||||
test(OrderG, OrderAlias)
|
|
||||||
|
|
||||||
typeRep(OrderAlias.R, Order.R) # true
|
|
||||||
typeRep(OrderR.R, Order.R) # true
|
|
||||||
typeRep(OrderG.R, Order.R) # true
|
|
||||||
|
|
||||||
typeRep(OrderR.R, OrderAlias.R) # true
|
|
||||||
typeRep(OrderG.R, OrderAlias.R) # true
|
|
||||||
typeRep(OrderR.R, OrderG.R) # true
|
|
||||||
|
|
||||||
echo OrderR.R # R
|
|
||||||
echo OrderG.R # R
|
|
||||||
echo OrderAlias.R # R
|
|
||||||
echo Order.R # R
|
|
||||||
|
|
@ -1,25 +0,0 @@
|
||||||
|
|
||||||
# bug #4124
|
|
||||||
|
|
||||||
import sequtils
|
|
||||||
|
|
||||||
type
|
|
||||||
Foo = distinct string
|
|
||||||
|
|
||||||
var
|
|
||||||
foo: Foo
|
|
||||||
|
|
||||||
type
|
|
||||||
Alias = (type(foo))
|
|
||||||
var
|
|
||||||
a: Alias
|
|
||||||
|
|
||||||
a = foo
|
|
||||||
|
|
||||||
when true:
|
|
||||||
var xs = @[1,2,3]
|
|
||||||
|
|
||||||
proc asFoo(i: string): Foo =
|
|
||||||
Foo(i)
|
|
||||||
|
|
||||||
var xx = xs.mapIt(asFoo($(it + 5)))
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue