File: taliasbugs.nim

package info (click to toggle)
nim 0.19.4-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 462,356 kB
  • sloc: sh: 11,089; ansic: 4,699; makefile: 706; python: 309; sql: 297; asm: 141; xml: 13
file content (169 lines) | stat: -rw-r--r-- 2,336 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
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)))


when false:
  type
    FooObj[T] = object
      v: T
    Foo1[T] = FooObj[T]
    Foo2 = FooObj
    Foo1x = Foo1
    Foo12x = Foo1 | Foo2
    Foo2x = Foo2  # Error: illegal recursion in type 'Foo2x'