From a1e29f882ca0a0818be8535482535f9bb9144d52 Mon Sep 17 00:00:00 2001 From: Timothee Cour Date: Mon, 20 Aug 2018 11:10:08 -0700 Subject: [PATCH] used a different implementation to bypass issue #8693 --- lib/pure/typetraits.nim | 9 ++++++--- tests/metatype/ttypetraits2.nim | 31 +++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 3 deletions(-) create mode 100644 tests/metatype/ttypetraits2.nim diff --git a/lib/pure/typetraits.nim b/lib/pure/typetraits.nim index bd52f79d9e3fa..077f6b31a4b69 100644 --- a/lib/pure/typetraits.nim +++ b/lib/pure/typetraits.nim @@ -10,6 +10,8 @@ ## This module defines compile-time reflection procs for ## working with types +import macros + proc name*(t: typedesc): string {.magic: "TypeTrait".} ## Returns the name of the given type. ## @@ -57,7 +59,7 @@ proc supportsCopyMem*(t: typedesc): bool {.magic: "TypeTrait".} ## This trait returns true iff the type ``t`` is safe to use for ## `copyMem`:idx:. Other languages name a type like these `blob`:idx:. -proc `==`*(t1, t2: typedesc): bool = +macro `==`*(t1, t2: typedesc): untyped = ## Returns whether ``t1`` and ``t2`` are the same type; this is different ## from ``t1 is t2`` since the latter supports concepts & inheritance. runnableExamples: @@ -65,8 +67,9 @@ proc `==`*(t1, t2: typedesc): bool = doAssert T == int doAssert int == T doAssert: int != float - t1 is t2 and t2 is t1 + # Note: t1 is t2 and t2 is t1 ran into https://github.com/nim-lang/Nim/issues/8693 + newLit sameType(t1.getType[1], t2.getType[1]) when isMainModule: doAssert $type(42) == "int" - discard int == int ## pending https://github.com/nim-lang/Nim/issues/7280 + discard int == int # pending https://github.com/nim-lang/Nim/issues/7280 diff --git a/tests/metatype/ttypetraits2.nim b/tests/metatype/ttypetraits2.nim new file mode 100644 index 0000000000000..d8a9e113d5d92 --- /dev/null +++ b/tests/metatype/ttypetraits2.nim @@ -0,0 +1,31 @@ +discard """ +""" + +# NOTE: ttypetraits.nim is disabled, so using typetraits2.nim +import typetraits + +block sameType: + doAssert int == int + + type Foo = int | float + doAssert Foo == Foo + doAssert: Foo != int + doAssert: int != Foo + + type myInt = distinct int + doAssert myInt == myInt + doAssert: int != myInt + + type Foo2 = float | int + when false: + # TODO: this fails + doAssert Foo2 == Foo + + type A=object of RootObj + b1:int + + type B=object of A + b2:int + doAssert: A != B + doAssert: B != A + doAssert B == B