Skip to content

Commit

Permalink
used a different implementation to bypass issue #8693
Browse files Browse the repository at this point in the history
  • Loading branch information
timotheecour committed Aug 22, 2018
1 parent 06de483 commit a1e29f8
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 3 deletions.
9 changes: 6 additions & 3 deletions lib/pure/typetraits.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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.
##
Expand Down Expand Up @@ -57,16 +59,17 @@ 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:
type T = int
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
31 changes: 31 additions & 0 deletions tests/metatype/ttypetraits2.nim
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit a1e29f8

Please sign in to comment.