fix is with generic types; fix genericHead(Foo[T]) (#13303)

* fix #9855, fix #9855, fix genericHead
* render TTypeKind via toHumanStr
This commit is contained in:
Timothee Cour 2020-02-09 04:48:55 -08:00 • committed by GitHub
commit 7939319379
7 changed files with 94 additions and 20 deletions

View file

@ -47,7 +47,7 @@ block: # typeToString
doAssert MyInt.name3 == "MyInt{int}"
doAssert (tuple[a: MyInt, b: float]).name3 == "tuple[a: MyInt{int}, b: float]"
doAssert (tuple[a: C2b[MyInt, C4[cstring]], b: cint, c: float]).name3 ==
"tuple[a: C2b{C}[MyInt{int}, C4[cstring]], b: cint{int32}, c: float]"
"tuple[a: C[MyInt{int}, C4[cstring]], b: cint{int32}, c: float]"
block distinctBase:
block:
@ -125,4 +125,33 @@ var x = CpuStorage[string]()
static:
doAssert(not string.supportsCopyMem)
doAssert x.T is string # true
doAssert x.raw_buffer is seq
doAssert x.raw_buffer is seq
block genericHead:
type Foo[T1,T2] = object
x1: T1
x2: T2
type FooInst = Foo[int, float]
type Foo2 = genericHead(FooInst)
doAssert Foo2 is Foo # issue #13066
block:
type Goo[T] = object
type Moo[U] = object
type Hoo = Goo[Moo[float]]
type Koo = genericHead(Hoo)
doAssert Koo is Goo
doAssert genericParams(Hoo) is (Moo[float],)
doAssert genericParams(Hoo).get(0) is Moo[float]
doAssert genericHead(genericParams(Hoo).get(0)) is Moo
type Foo2Inst = Foo2[int, float]
doAssert FooInst.default == Foo2Inst.default
doAssert FooInst.default.x2 == 0.0
doAssert Foo2Inst is FooInst
doAssert FooInst is Foo2Inst
doAssert compiles(genericHead(FooInst))
doAssert not compiles(genericHead(Foo))
type Bar = object
doAssert not compiles(genericHead(Bar))
# doAssert seq[int].genericHead is seq

View file

@ -89,3 +89,23 @@ proc test[T](x: T) =
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)