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:
metagn
2024-12-09 10:11:47 +03:00
committed by GitHub
parent d408b94063
commit aeb3fe9505
27 changed files with 393 additions and 0 deletions

View File

@@ -0,0 +1,7 @@
block: # issue #13184
type
TypeClass = uint | enum | int
ArrayAlias[I: TypeClass] = array[I, int]
proc test[I: TypeClass](points: ArrayAlias[I]) =
discard

View File

@@ -0,0 +1,15 @@
discard """
action: compile
targets: "cpp"
matrix: "--compileOnly"
"""
# issue #20065
type
Foo* {.importC, nodecl.} = object # doesn't matter if this is importC or importCpp
value*: int64
Bar* {.importCpp, nodecl.} = object # no segfault with importC
foo*: Foo
discard @[Bar()]

View File

@@ -0,0 +1 @@
type Y* = object

View File

@@ -0,0 +1 @@
type Y* = object

View File

@@ -0,0 +1,14 @@
# issue #23510
import ./mambtype1
import ./mambtype2
proc u(d: int | int) =
var r: Y #[tt.Error
^ ambiguous identifier: 'Y' -- use one of the following:
mambtype1.Y: Y
mambtype2.Y: Y]#
static: doAssert r is j.Y # because j is imported first
doAssert r is j.Y
u(0)

View File

@@ -0,0 +1,6 @@
# issue #16439
import std/[strutils, sequtils]
var data = "aaa aaa"
echo data.split(" ").map(toSeq) #[tt.Error
^ type mismatch: got <seq[string], template (iter: untyped): untyped>]#

View 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())

View File

@@ -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'

View File

@@ -137,3 +137,22 @@ block: #3824
echo x
main()
block: # issue #12487
iterator FaiReader(): string {.closure.} =
yield "something"
template toClosure(i): auto =
iterator j: string {.closure.} =
for x in FaiReader():
yield x
j
proc main =
var reader = toClosure(FaiReader())
var s: seq[string] = @[]
for x in reader():
s.add(x)
doAssert s == @["something"]
main()

10
tests/iter/tsubscript.nim Normal file
View File

@@ -0,0 +1,10 @@
# issue #14860
type
Dummie = object
iterator `[]`(d: Dummie, a, b: int): int = discard
let d = Dummie()
for s in d[0, 1]: discard # error here

View File

@@ -0,0 +1,6 @@
# issue #19063
iterator items[T]*(s: seq[T]): T = #[tt.Error
^ invalid indentation; an export marker '*' follows the declared identifier]#
for i in system.items(s):
yield i

View File

@@ -0,0 +1,18 @@
# issue #12831
import std/[macros, strutils]
macro dumpRepr(x: typed): untyped =
result = newLit(x.treeRepr & "\n")
doAssert dumpRepr(`$`).startsWith("ClosedSymChoice")
# issue #19446
macro typedVarargs(x: varargs[typed]): untyped =
result = newLit($x[0].kind)
macro typedSingle(x: typed): untyped =
result = newLit($x.kind)
doAssert typedSingle(len) == "nnkClosedSymChoice"
doAssert typedVarargs(len) == "nnkClosedSymChoice"

View File

@@ -0,0 +1,11 @@
block: # issue #18314
type
A = ref object of RootObj
B = ref object of A
C = ref object of B
proc foo[T: A](a: T): string = "got A"
proc foo[T: B](b: T): string = "got B"
var c = C()
doAssert foo(c) == "got B"

View File

@@ -0,0 +1,8 @@
import std/options
type
Address* = object
port*: int
Node* = ref object
address*: Option[Address]

View File

@@ -88,3 +88,9 @@ proc foo(a = 0, b = a.high, c = high(typeof(a))) =
foo()
import std/strformat
block: # issue #18074
proc somefn[T](query: string, _: type[T], message = query) = discard
somefn(fmt"", string)

View File

@@ -0,0 +1,10 @@
# issue #22126
func foo[T](arr: openArray[T], idx: Natural = arr.high): int = # missed conversion: `Natural(arr.high)`
if idx == 0:
return 0
foo(arr, idx - 1)
let arr = [0, 1, 2]
doAssert foo(arr) == 0

View File

@@ -0,0 +1,14 @@
# issue #23020
proc n[T: bool](k: int | int) =
#static:
# doAssert T is bool
# doAssert T isnot int
# And runtime
block:
doAssert T is bool
doAssert T isnot int
n[int](0) #[tt.Error
^ type mismatch: got <int literal(0)>]#

View File

@@ -61,3 +61,19 @@ block: # explicit generic with unresolved generic param, https://forum.nim-lang.
var x = [1, 1]
discard MyMedian(x) # emits "1\n"
doAssert s == @["1"]
block: # issue #16153
type
X[T] = openArray[T] | varargs[T] | seq[T]
Y[T] = ref object
dll: T
proc initY[T](): Y[T] =
new(result)
proc initY[T](v: X[T]): Y[T] =
new(result)
for e in v:
echo e
var deque: Y[int] = initY[int]()

View File

@@ -135,6 +135,22 @@ block: # issue #7008
explicitGenericProc1(n, 5) # works
explicitGenericProc2(n, 5) # doesn't
block: # issue #7009
type Node[T] = object
val: T
proc genericProc(s: Node; key: s.T) =
discard # body doesn't matter
proc explicitGenericProc[T](s: Node[T]; key: T) =
discard # body doesn't matter
proc concreteProc(s: Node[cstring]; key: s.T) =
discard # body doesn't matter
var strs: Node[cstring]
concreteProc(strs, "string") # string converts to cstring
explicitGenericProc(strs, "string") # still converts
genericProc(strs, "string") # doesn't convert: COMPILE ERROR
block: # issue #20027
block:
type Test[T] = object
@@ -266,3 +282,9 @@ block: # issue #22276
a = x * 2)
doAssert a == 18
foo(B, proc (x: float) = doAssert x == 9)
block: # issue #9190
func foo[T, U]: type(T.low + U.low) =
T.low + U.low
doAssert foo[uint8, uint8]() == uint8.low

View File

@@ -0,0 +1,13 @@
# issue #22820
{.push raises: [].}
import
"."/[msugarcrash1]
import
std/[options, sugar]
var closestNodes: seq[Node]
for cn in closestNodes:
discard cn.address.map(a => a.port)

View File

@@ -0,0 +1,7 @@
# issue #22888
proc dummy*[T: SomeNumber](a: T, b: T = 2.5): T = #[tt.Error
^ type mismatch: got <float64> but expected 'int']#
result = a
echo dummy(2)

View File

@@ -0,0 +1,12 @@
block: # issue #6013
type
n16 = range[0'i16..high(int16)]
SomeObj = ref object
proc doSomethingMore(idOrObj: n16 or SomeObj) =
discard
proc doSomething(idOrObj: n16 or SomeObj) =
doSomethingMore(idOrObj) # Error: type mismatch: got (int16)
doSomething(0.n16)

View File

@@ -0,0 +1,17 @@
# issue #17779
{.experimental: "dotOperators".}
type
Flag = enum
A
Flags = set[Flag]
template `.=`*(flags: Flags, key: Flag, val: bool) =
if val: flags.incl key else: flags.excl key
var flags: Flags
flags.A = 123 #[tt.Error
^ undeclared field: 'A=' for type tmismatch.Flags [type declared in tmismatch.nim(9, 5)]]#

View File

@@ -80,3 +80,10 @@ macro bindmeQuote*(): untyped =
var ss = newStringStream("anothertext")
ss.writeData(tst[0].addr, 2)
discard ss.readData(tst[0].addr, 2) # <= comment this out to make compilation successful
# issue #14894
proc myProc(s: string) = discard
template myTemplate* =
"".myProc

View File

@@ -30,3 +30,6 @@ block: # issue #7889
bindmeQuote()
if false:
bindmeTemplate()
block: # issue #14894
myTemplate()

View File

@@ -0,0 +1,14 @@
discard """
action: compile
"""
# issue #18648
type
X* = ref object
bar: proc (p: proc(v: openArray[byte]))
template foo(x: X, p: proc(v: openArray[byte])) =
x.bar(p)
X().foo(proc(v: openArray[byte]) = discard @v)

View File

@@ -0,0 +1,50 @@
discard """
output: '''
1
2
3
FooBar
foo1
foo2
foo3
seq[int]
@[5, 6]
'''
"""
# issue #13252
import macros
type
FooBar = object
a: seq[int]
macro genFoobar(fb: static FooBar): untyped =
result = newStmtList()
for b in fb.a:
result.add(newCall(bindSym"echo", newLit b))
proc foobar(fb: static FooBar) =
genFoobar(fb)
echo fb.type # added line, same error when wrapped in static:
# Error: undeclared field: 'a'
for b in fb.a:
echo "foo" & $b
proc main() =
const a: seq[int] = @[1, 2, 3]
const fb = Foobar(a: a)
foobar(fb)
main()
# issue #14917
proc passSeq2[T](a : static seq[T]) =
echo a
template passSeq1[T](a : static seq[T]) =
echo type(a)
passSeq2(a)
passSeq1(@[5,6])