123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112 |
- 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)
|