mirror of
https://github.com/nim-lang/Nim.git
synced 2026-02-17 16:38:33 +00:00
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:
@@ -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
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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"
|
||||
|
||||
8
tests/template/tqualifiedident.nim
Normal file
8
tests/template/tqualifiedident.nim
Normal 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()
|
||||
Reference in New Issue
Block a user