second test case haul for templates and generics (#22728)

closes #8390, closes #11726, closes #8446, closes #21221, closes #7461,
closes #7995
This commit is contained in:
metagn
2023-09-19 10:26:26 +03:00
committed by GitHub
parent 51cb493b22
commit 81756d1810
6 changed files with 62 additions and 6 deletions

View File

@@ -231,3 +231,10 @@ doSomething(identity((1, 2)))
proc myProc[T, U](x: T or U) = discard
myProc[int, string](x = 2)
block: # issue #8390
proc x[T:SomeFloat](q: openarray[T], y: T = 1): string =
doAssert $q.type == $openarray[y.type]
$y.type
doAssert x(@[1.0]) == $1.0.type

View File

@@ -1,3 +1,14 @@
func r(): auto =
func(): int = 2
discard r()()
doAssert r()() == 2
block: # issue #11726
let foo = block:
var x: int
proc = inc x # "identifier expected, but got '='"
template paint(): untyped =
proc (s: string): string = s
let s = paint()
doAssert s("abc") == "abc"

View File

@@ -411,6 +411,27 @@ block: # Ensure static descriminated objects compile
discard instance
discard MyObject[KindC]()
block: # more cases of above, issue #8446
type
Color = enum
red, green, blue
Blah[color: static[Color]] = object
when color == red:
a: string
else:
b: int
proc foo(blah: Blah) = discard
foo(Blah[red](a: "abc"))
type
Mytype[K: static[int]] = object
when K < 16:
data: uint8
else:
data: uint64
proc usingMyt(k: Mytype) = discard # triggers Error: cannot generate code for: K
block: # bug #22600
proc f(n: static int): int = n * 2 # same for template

View File

@@ -302,7 +302,3 @@ block: # bug #21920
discard
t[void]() # Error: expression has no type: discard
block: # issue #19865
template f() = discard default(system.int)
f()

View File

@@ -36,7 +36,7 @@ block: # basic template generic parameter substitution
template run[T](): T = default(T)
doAssert run[int]() == 0
import options, tables
import options, tables, typetraits
block: # complex cases of above with imports
block: # issue #19576, complex case
@@ -78,3 +78,16 @@ block: # complex cases of above with imports
else:
Foo.init(A,"hi")
let op = fromOption(some(5))
block: # issue #7461
template p[T](): untyped = none(T)
doAssert p[int]() == none(int)
block: # issue #7995
var res: string
template copyRange[T](dest: seq[T], destOffset: int) =
when supportsCopyMem(T):
res = "A"
else:
res = "B"
var a = @[1, 2, 3]
copyRange(a, 0)
doAssert res == "A"

View File

@@ -0,0 +1,8 @@
block: # issue #19865
template f() = discard default(system.int)
f()
# issue #21221, same as above
type M = object
template r() = discard default(tqualifiedident.M)
r()