summary refs log tree commit diff stats
path: root/tests/generics/tforwardgenericconstrained.nim
blob: 6163ea1a87f90ef1096746678596340d81d01836 (plain) (blame)
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
discard """
output: '''
hello some integer
hello range
hello tuple
hello seq
hello object
hello distinct
hello enum
'''
"""



# SomeInteger

proc foo[T : SomeInteger](arg: T)
proc foo[T : SomeInteger](arg: T) =
  echo "hello some integer"
foo(123)

# range

proc foo2[T : range[0..100]](arg: T)
proc foo2[T : range[0..100]](arg: T) =
  echo "hello range"
foo2(7)

# tuple

proc foo3[T : tuple](arg: T)
proc foo3[T : tuple](arg: T) =
  echo "hello tuple"

foo3((a:123,b:321))

# seq

proc foo4[T: seq](arg: T)
proc foo4[T: seq](arg: T) =
  echo "hello seq"

foo4(@[1,2,3])

# object

proc foo5[T : object](arg: T)
proc foo5[T : object](arg: T) =
  echo "hello object"

type MyType = object
var mt: MyType
foo5(mt)

# distinct

proc foo6[T : distinct](arg: T)
proc foo6[T : distinct](arg: T) =
  echo "hello distinct"

type MyDistinct = distinct string
var md: MyDistinct
foo6(md)

# enum

proc foo7[T : enum](arg: T)
proc foo7[T : enum](arg: T) =
  echo "hello enum"

type MyEnum = enum
  ValueA
foo7(ValueA)