From aeb3fe9505f7d1ef3efcd0001541a64ca8382b01 Mon Sep 17 00:00:00 2001 From: metagn Date: Mon, 9 Dec 2024 10:11:47 +0300 Subject: [PATCH] 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 --- tests/array/tgenericindex.nim | 7 +++ tests/cpp/timportedtypecrash.nim | 15 ++++++ tests/errmsgs/mambtype1.nim | 1 + tests/errmsgs/mambtype2.nim | 1 + tests/errmsgs/tambtype.nim | 14 ++++++ tests/errmsgs/ttemplateaslambda.nim | 6 +++ tests/generics/ttemplateparamcall.nim | 47 +++++++++++++++++ .../generics/tuninstantiatedgenericcalls.nim | 39 +++++++++++++++ tests/iter/tnestedclosures.nim | 19 +++++++ tests/iter/tsubscript.nim | 10 ++++ tests/lexer/titerwrongexport.nim | 6 +++ tests/macros/ttypedsymchoice.nim | 18 +++++++ tests/overload/tsubtypegenericconstraint.nim | 11 ++++ tests/proc/msugarcrash1.nim | 8 +++ tests/proc/tdefaultprocparam.nim | 6 +++ tests/proc/tdefaultvalueconv.nim | 10 ++++ tests/proc/texplicitgenericconstraint.nim | 14 ++++++ tests/proc/texplicitgenerics.nim | 16 ++++++ tests/proc/tstaticsignature.nim | 22 ++++++++ tests/proc/tsugarcrash1.nim | 13 +++++ tests/proc/twrongdefaultvalue2.nim | 7 +++ tests/range/tintypeclass.nim | 12 +++++ tests/specialops/tmismatch.nim | 17 +++++++ tests/template/mdotcall.nim | 7 +++ tests/template/tdotcall.nim | 3 ++ tests/template/tlambdaparam.nim | 14 ++++++ tests/vm/tconstarrayresem2.nim | 50 +++++++++++++++++++ 27 files changed, 393 insertions(+) create mode 100644 tests/array/tgenericindex.nim create mode 100644 tests/cpp/timportedtypecrash.nim create mode 100644 tests/errmsgs/mambtype1.nim create mode 100644 tests/errmsgs/mambtype2.nim create mode 100644 tests/errmsgs/tambtype.nim create mode 100644 tests/errmsgs/ttemplateaslambda.nim create mode 100644 tests/generics/ttemplateparamcall.nim create mode 100644 tests/iter/tsubscript.nim create mode 100644 tests/lexer/titerwrongexport.nim create mode 100644 tests/macros/ttypedsymchoice.nim create mode 100644 tests/overload/tsubtypegenericconstraint.nim create mode 100644 tests/proc/msugarcrash1.nim create mode 100644 tests/proc/tdefaultvalueconv.nim create mode 100644 tests/proc/texplicitgenericconstraint.nim create mode 100644 tests/proc/tsugarcrash1.nim create mode 100644 tests/proc/twrongdefaultvalue2.nim create mode 100644 tests/range/tintypeclass.nim create mode 100644 tests/specialops/tmismatch.nim create mode 100644 tests/template/tlambdaparam.nim create mode 100644 tests/vm/tconstarrayresem2.nim diff --git a/tests/array/tgenericindex.nim b/tests/array/tgenericindex.nim new file mode 100644 index 0000000000000..ec5020c6572bf --- /dev/null +++ b/tests/array/tgenericindex.nim @@ -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 diff --git a/tests/cpp/timportedtypecrash.nim b/tests/cpp/timportedtypecrash.nim new file mode 100644 index 0000000000000..1bf901a0558e1 --- /dev/null +++ b/tests/cpp/timportedtypecrash.nim @@ -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()] diff --git a/tests/errmsgs/mambtype1.nim b/tests/errmsgs/mambtype1.nim new file mode 100644 index 0000000000000..a50bfc1e895a9 --- /dev/null +++ b/tests/errmsgs/mambtype1.nim @@ -0,0 +1 @@ +type Y* = object diff --git a/tests/errmsgs/mambtype2.nim b/tests/errmsgs/mambtype2.nim new file mode 100644 index 0000000000000..a50bfc1e895a9 --- /dev/null +++ b/tests/errmsgs/mambtype2.nim @@ -0,0 +1 @@ +type Y* = object diff --git a/tests/errmsgs/tambtype.nim b/tests/errmsgs/tambtype.nim new file mode 100644 index 0000000000000..29b63f8c3cc9d --- /dev/null +++ b/tests/errmsgs/tambtype.nim @@ -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) diff --git a/tests/errmsgs/ttemplateaslambda.nim b/tests/errmsgs/ttemplateaslambda.nim new file mode 100644 index 0000000000000..0c24081a6d70a --- /dev/null +++ b/tests/errmsgs/ttemplateaslambda.nim @@ -0,0 +1,6 @@ +# issue #16439 + +import std/[strutils, sequtils] +var data = "aaa aaa" +echo data.split(" ").map(toSeq) #[tt.Error + ^ type mismatch: got ]# diff --git a/tests/generics/ttemplateparamcall.nim b/tests/generics/ttemplateparamcall.nim new file mode 100644 index 0000000000000..6525c3f08922f --- /dev/null +++ b/tests/generics/ttemplateparamcall.nim @@ -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 + t(a, h) + +e(L(), R()) +e(B(), R()) diff --git a/tests/generics/tuninstantiatedgenericcalls.nim b/tests/generics/tuninstantiatedgenericcalls.nim index b21c1f981db9c..64b6143f28164 100644 --- a/tests/generics/tuninstantiatedgenericcalls.nim +++ b/tests/generics/tuninstantiatedgenericcalls.nim @@ -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 + 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' diff --git a/tests/iter/tnestedclosures.nim b/tests/iter/tnestedclosures.nim index 273c4aa303d01..e23fa1355fe6d 100644 --- a/tests/iter/tnestedclosures.nim +++ b/tests/iter/tnestedclosures.nim @@ -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() diff --git a/tests/iter/tsubscript.nim b/tests/iter/tsubscript.nim new file mode 100644 index 0000000000000..31c3e693dd05c --- /dev/null +++ b/tests/iter/tsubscript.nim @@ -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 diff --git a/tests/lexer/titerwrongexport.nim b/tests/lexer/titerwrongexport.nim new file mode 100644 index 0000000000000..c337bcacc4096 --- /dev/null +++ b/tests/lexer/titerwrongexport.nim @@ -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 diff --git a/tests/macros/ttypedsymchoice.nim b/tests/macros/ttypedsymchoice.nim new file mode 100644 index 0000000000000..8272528525059 --- /dev/null +++ b/tests/macros/ttypedsymchoice.nim @@ -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" diff --git a/tests/overload/tsubtypegenericconstraint.nim b/tests/overload/tsubtypegenericconstraint.nim new file mode 100644 index 0000000000000..90a1ece4036c7 --- /dev/null +++ b/tests/overload/tsubtypegenericconstraint.nim @@ -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" diff --git a/tests/proc/msugarcrash1.nim b/tests/proc/msugarcrash1.nim new file mode 100644 index 0000000000000..a743d6cce44e3 --- /dev/null +++ b/tests/proc/msugarcrash1.nim @@ -0,0 +1,8 @@ +import std/options + +type + Address* = object + port*: int + + Node* = ref object + address*: Option[Address] diff --git a/tests/proc/tdefaultprocparam.nim b/tests/proc/tdefaultprocparam.nim index 90edfa8c93bca..f2e357a535f04 100644 --- a/tests/proc/tdefaultprocparam.nim +++ b/tests/proc/tdefaultprocparam.nim @@ -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) + diff --git a/tests/proc/tdefaultvalueconv.nim b/tests/proc/tdefaultvalueconv.nim new file mode 100644 index 0000000000000..48c20654b8f78 --- /dev/null +++ b/tests/proc/tdefaultvalueconv.nim @@ -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 diff --git a/tests/proc/texplicitgenericconstraint.nim b/tests/proc/texplicitgenericconstraint.nim new file mode 100644 index 0000000000000..79779dfc08ad0 --- /dev/null +++ b/tests/proc/texplicitgenericconstraint.nim @@ -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 ]# diff --git a/tests/proc/texplicitgenerics.nim b/tests/proc/texplicitgenerics.nim index 131a31458d5c2..ef60ac3f3c034 100644 --- a/tests/proc/texplicitgenerics.nim +++ b/tests/proc/texplicitgenerics.nim @@ -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]() diff --git a/tests/proc/tstaticsignature.nim b/tests/proc/tstaticsignature.nim index 25aa09c5dfe87..9a0a032703907 100644 --- a/tests/proc/tstaticsignature.nim +++ b/tests/proc/tstaticsignature.nim @@ -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 diff --git a/tests/proc/tsugarcrash1.nim b/tests/proc/tsugarcrash1.nim new file mode 100644 index 0000000000000..9c268d25d2c1a --- /dev/null +++ b/tests/proc/tsugarcrash1.nim @@ -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) diff --git a/tests/proc/twrongdefaultvalue2.nim b/tests/proc/twrongdefaultvalue2.nim new file mode 100644 index 0000000000000..1953c8204c702 --- /dev/null +++ b/tests/proc/twrongdefaultvalue2.nim @@ -0,0 +1,7 @@ +# issue #22888 + +proc dummy*[T: SomeNumber](a: T, b: T = 2.5): T = #[tt.Error + ^ type mismatch: got but expected 'int']# + result = a + +echo dummy(2) diff --git a/tests/range/tintypeclass.nim b/tests/range/tintypeclass.nim new file mode 100644 index 0000000000000..7606f80a3e5d9 --- /dev/null +++ b/tests/range/tintypeclass.nim @@ -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) diff --git a/tests/specialops/tmismatch.nim b/tests/specialops/tmismatch.nim new file mode 100644 index 0000000000000..76c921b14a9ed --- /dev/null +++ b/tests/specialops/tmismatch.nim @@ -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)]]# diff --git a/tests/template/mdotcall.nim b/tests/template/mdotcall.nim index fecd8ee2661b6..ecd46124192cb 100644 --- a/tests/template/mdotcall.nim +++ b/tests/template/mdotcall.nim @@ -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 diff --git a/tests/template/tdotcall.nim b/tests/template/tdotcall.nim index dc97fd52e6cdf..b339198a1021e 100644 --- a/tests/template/tdotcall.nim +++ b/tests/template/tdotcall.nim @@ -30,3 +30,6 @@ block: # issue #7889 bindmeQuote() if false: bindmeTemplate() + +block: # issue #14894 + myTemplate() diff --git a/tests/template/tlambdaparam.nim b/tests/template/tlambdaparam.nim new file mode 100644 index 0000000000000..ad69a8448cc58 --- /dev/null +++ b/tests/template/tlambdaparam.nim @@ -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) diff --git a/tests/vm/tconstarrayresem2.nim b/tests/vm/tconstarrayresem2.nim new file mode 100644 index 0000000000000..99096160f3404 --- /dev/null +++ b/tests/vm/tconstarrayresem2.nim @@ -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])