mirror of
https://github.com/nim-lang/Nim.git
synced 2026-08-31 02:43:41 +00:00
test case haul to prevent pileup (#24525)
closes #6013, closes #7009, closes #9190, closes #12487, closes #12831, closes #13184, closes #13252, closes #14860, closes #14877, closes #14894, closes #14917, closes #16153, closes #16439, closes #17779, closes #18074, closes #18202, closes #18314, closes #18648, closes #19063, closes #19446, closes #20065, closes #20367, closes #22126, closes #22820, closes #22888, closes #23020, closes #23287, closes #23510
This commit is contained in:
47
tests/generics/ttemplateparamcall.nim
Normal file
47
tests/generics/ttemplateparamcall.nim
Normal file
@@ -0,0 +1,47 @@
|
||||
discard """
|
||||
output: '''
|
||||
L
|
||||
L
|
||||
L
|
||||
L
|
||||
B
|
||||
B
|
||||
B
|
||||
B
|
||||
'''
|
||||
"""
|
||||
|
||||
# issue #18202
|
||||
|
||||
type
|
||||
R = object
|
||||
S = object
|
||||
U = R | S
|
||||
|
||||
L = object
|
||||
B = object
|
||||
C = B | L
|
||||
|
||||
proc f(n: L, q: R | S) = echo "L"
|
||||
proc f(n: B, q: R | S) = echo "B"
|
||||
|
||||
proc g(n: C, q: R | S) = echo (when n is L: "L" else: "B")
|
||||
|
||||
proc h(n: L, q: U) = echo "L"
|
||||
proc h(n: B, q: U) = echo "B"
|
||||
|
||||
proc j(n: C, q: U) = echo (when n is L: "L" else: "B")
|
||||
|
||||
proc e(n: B | L, a: R) =
|
||||
template t(operations: untyped, fn: untyped) = fn(n, operations)
|
||||
|
||||
# Work as expected
|
||||
t(a, f)
|
||||
t(a, g)
|
||||
t(a, j)
|
||||
|
||||
# Error: type mismatch: got <R, proc [*missing parameters*](n: B, q: U) | proc [*missing parameters*](n: L, q: U)>
|
||||
t(a, h)
|
||||
|
||||
e(L(), R())
|
||||
e(B(), R())
|
||||
@@ -353,6 +353,11 @@ block: # issue #15959
|
||||
my3(x, x)
|
||||
doAssert not compiles(my3(x, x[0]))
|
||||
|
||||
block: # issue #14877
|
||||
proc fn[T](a: T, index: int): typeof(a.x) = a.x # ok
|
||||
proc fn2(a: seq[int], index: int): typeof(a[0]) = a[index] # ok
|
||||
proc fn3[T](a: T, index: int): typeof(a[0]) = a[index] # Error: type mismatch: got <T, int literal(0)>
|
||||
|
||||
block: # issue #22342, type section version of #22607
|
||||
type GenAlias[isInt: static bool] = (
|
||||
when isInt:
|
||||
@@ -515,3 +520,37 @@ block: # issue #16175
|
||||
var s = Thing[1]()
|
||||
doAssert s.kid is Thing[0.uint]
|
||||
doAssert s.kid.kid is char
|
||||
|
||||
block: # issue #23287
|
||||
template emitTupleType(trait: typedesc): untyped =
|
||||
trait
|
||||
|
||||
type
|
||||
Traitor[Traits] = ref object of RootObj ##
|
||||
vtable: emitTupleType(Traits)
|
||||
|
||||
type Generic[X] = object
|
||||
|
||||
proc test2[Traits](val: Traitor[Generic[Traits]]) =
|
||||
static: assert val.vtable is Generic[int]
|
||||
|
||||
proc test[X](val: Traitor[Generic[X]]) = discard
|
||||
|
||||
test2 Traitor[Generic[int]]() # This should error, but passes
|
||||
test Traitor[Generic[int]]()
|
||||
|
||||
block: # issue #20367, example 1
|
||||
template someTemp(T:type):typedesc = T
|
||||
type
|
||||
Foo[T2] = someTemp(T2)
|
||||
Bar[T1] = Foo[T1]
|
||||
var u:Foo[float] # works
|
||||
var v:Bar[float] # Error: invalid type: 'None' in this context: 'Bar[system.float]' for var
|
||||
|
||||
block: # issue #20367, example 2
|
||||
template someOtherTemp(p:static[int]):untyped = array[p,int]
|
||||
type
|
||||
Foo2[n:static[int]] = someOtherTemp(n)
|
||||
Bar2[m:static[int]] = Foo2[m]
|
||||
var x:Foo2[1] # works
|
||||
var y:Bar2[1] # Error: undeclared identifier: 'n'
|
||||
|
||||
Reference in New Issue
Block a user