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 170 171
|
discard """
output: '''true true false yes
false
true
false
true
true
yes'''
"""
proc IsVoid[T](): string =
when T is void:
result = "yes"
else:
result = "no"
const x = int is int
echo x, " ", float is float, " ", float is string, " ", IsVoid[void]()
template yes(e): void =
static: assert e
template no(e): void =
static: assert(not e)
when false:
var s = @[1, 2, 3]
yes s.items is iterator
no s.items is proc
yes s.items is iterator: int
no s.items is iterator: float
yes s.items is iterator: TNumber
no s.items is iterator: object
type
Iter[T] = iterator: T
yes s.items is Iter[TNumber]
no s.items is Iter[float]
type
Foo[N: static[int], T] = object
field: array[1..N, T]
Bar[T] = Foo[4, T]
Baz[N: static[int]] = Foo[N, float]
no Foo[2, float] is Foo[3, float]
no Foo[2, float] is Foo[2, int]
yes Foo[4, string] is Foo[4, string]
yes Bar[int] is Foo[4, int]
yes Foo[4, int] is Bar[int]
no Foo[4, int] is Baz[4]
yes Foo[4, float] is Baz[4]
# bug #2505
echo(8'i8 is int32)
# bug #1853
type SeqOrSet[E] = seq[E] or set[E]
type SeqOfInt = seq[int]
type SeqOrSetOfInt = SeqOrSet[int]
# This prints "true", as expected. Previously "false" was returned and that
# seemed less correct that (1) printing "true" or (2) raising a compiler error.
echo seq is SeqOrSet
# This prints "false", as expected.
echo seq is SeqOrSetOfInt
# This prints "true", as expected.
echo SeqOfInt is SeqOrSet
# This causes an internal error (filename: compiler/semtypes.nim, line: 685).
echo SeqOfInt is SeqOrSetOfInt
# bug #2522
proc test[T](x: T) =
when T is typedesc:
echo "yes"
else:
echo "no"
test(7)
block:
# bug #13066
type Bar[T1,T2] = object
type Foo[T1,T2] = object
type Foo2 = Foo
doAssert Foo2 is Foo
doAssert Foo is Foo2
doAssert Foo is Foo
doAssert Foo2 is Foo2
doAssert Foo2 isnot Bar
doAssert Foo[int,float] is Foo2[int,float]
# other
doAssert Foo[int,float] isnot Foo2[float,float]
doAssert Foo[int,float] is Foo2
doAssert Foo[int,float|int] is Foo2
doAssert Foo2[int,float|int] is Foo
doAssert Foo2[int,float|int] isnot Bar
doAssert int is (int|float)
block:
# Slice[T] as static type issue
type
MyEnum = enum
x1, x2, x3, x4, x5, x6
proc enumGen[T: enum](s: static[Slice[T]]) =
doAssert($s.a & " " & $s.b == "x1 x3")
enumGen(x1..x3)
block:
# issue #11142
type
MyObjParam[N: static int] = object
x: int
MyObj[P: static MyObjParam] = object
y: int
const P = MyObjParam[256](x: 2)
let Q = MyObj[P](y: 2)
doAssert($Q == "(y: 2)")
block: # previously tisop.nim
type
TRecord = (tuple) or (object)
TFoo[T, U] = object
x: int
when T is string:
y: float
else:
y: string
when U is TRecord:
z: float
E = enum A, B, C
template m(t: typedesc): typedesc =
when t is enum:
string
else:
int
var f: TFoo[int, int]
static: doAssert(typeof(f.y) is string)
when compiles(f.z):
{.error: "Foo should not have a `z` field".}
proc p(a, b: auto) =
when typeof(a) is int:
static: doAssert false
var f: TFoo[m(a.typeof), b.typeof]
static:
doAssert f.x.typeof is int
doAssert f.y.typeof is float
doAssert f.z.typeof is float
p(A, f)
block: # issue #22850
doAssert not (type is int)
doAssert not (typedesc is int)
|