From 9db9b8ce5783ced38bda00f296a98b97d82e530b Mon Sep 17 00:00:00 2001 From: ringabout <43030857+ringabout@users.noreply.github.com> Date: Sat, 13 Jun 2026 11:06:51 +0800 Subject: [PATCH] adds regression tests (#25906) closes #22842, closes #21252, closes #19312, closes #16956, closes #16416, closes #14913, closes #13296, closes #12424, closes #10902, closes #9892, closes #9617 --- tests/arc/t19312.nim | 19 +++++++++++++++++++ tests/async/t16416.nim | 17 +++++++++++++++++ tests/concepts/t14913.nim | 23 +++++++++++++++++++++++ tests/destructor/t9617.nim | 20 ++++++++++++++++++++ tests/errmsgs/t16956.nim | 11 +++++++++++ tests/generics/t21252.nim | 35 +++++++++++++++++++++++++++++++++++ tests/macros/t10902.nim | 31 +++++++++++++++++++++++++++++++ tests/macros/t13296.nim | 21 +++++++++++++++++++++ tests/macros/t9892.nim | 16 ++++++++++++++++ tests/pragmas/t12424.nim | 8 ++++++++ tests/typerel/t22842.nim | 11 +++++++++++ 11 files changed, 212 insertions(+) create mode 100644 tests/arc/t19312.nim create mode 100644 tests/async/t16416.nim create mode 100644 tests/concepts/t14913.nim create mode 100644 tests/destructor/t9617.nim create mode 100644 tests/errmsgs/t16956.nim create mode 100644 tests/generics/t21252.nim create mode 100644 tests/macros/t10902.nim create mode 100644 tests/macros/t13296.nim create mode 100644 tests/macros/t9892.nim create mode 100644 tests/pragmas/t12424.nim create mode 100644 tests/typerel/t22842.nim diff --git a/tests/arc/t19312.nim b/tests/arc/t19312.nim new file mode 100644 index 0000000000..cded439ec7 --- /dev/null +++ b/tests/arc/t19312.nim @@ -0,0 +1,19 @@ +discard """ + matrix: "--mm:orc" + output: '''(val: 1) +(val: 1)''' +""" +# Issue #19312: copied ref object is converted to nil if not used in declaration module under ARC/ORC +# https://github.com/nim-lang/Nim/issues/19312 + +type + Wrapper* = object + val: int + RefWrapper* = ref Wrapper + +let + a* = RefWrapper(val: 1) + b* = a + +echo b[] +echo a[] diff --git a/tests/async/t16416.nim b/tests/async/t16416.nim new file mode 100644 index 0000000000..90ac695ffb --- /dev/null +++ b/tests/async/t16416.nim @@ -0,0 +1,17 @@ +discard """ + output: '''done''' +""" +# Issue #16416: Can't call closure iterator from inside an async function +# https://github.com/nim-lang/Nim/issues/16416 + +import asyncdispatch + +iterator x(): int {.closure.} = + yield 1 + +proc y() {.async.} = + for z in x(): + discard + +waitFor y() +echo "done" diff --git a/tests/concepts/t14913.nim b/tests/concepts/t14913.nim new file mode 100644 index 0000000000..3ef67b9f4c --- /dev/null +++ b/tests/concepts/t14913.nim @@ -0,0 +1,23 @@ +discard """ + output: '''done''' +""" +# Issue #14913: Compiler crash when using a default parameter value for a parameter whose type is a concept +# https://github.com/nim-lang/Nim/issues/14913 + +type + State = object + MoreState = object + StringRecord = concept x, type T + for k, v in fieldPairs(x): + k is string + v is string + StateStrings = object + a, b: string + +proc combine(a: State, b: MoreState): StateStrings = discard + +proc whoops[T: StringRecord](a: State, b: MoreState, c: T = a.combine(b)) = + discard + +whoops(State(), MoreState()) +echo "done" diff --git a/tests/destructor/t9617.nim b/tests/destructor/t9617.nim new file mode 100644 index 0000000000..260d458b24 --- /dev/null +++ b/tests/destructor/t9617.nim @@ -0,0 +1,20 @@ +discard """ + output: '''done''' +""" +# Issue #9617: Compiler error with sequences of destructible types +# https://github.com/nim-lang/Nim/issues/9617 + +type + Foo* = object + + Bar = ref object + s: seq[Foo] + +proc `=destroy`*(self: var Foo) = echo "hi" + +proc test(b: Bar) = + for i in b.s: + discard + +test(Bar()) +echo "done" diff --git a/tests/errmsgs/t16956.nim b/tests/errmsgs/t16956.nim new file mode 100644 index 0000000000..25e3e4cec8 --- /dev/null +++ b/tests/errmsgs/t16956.nim @@ -0,0 +1,11 @@ +discard """ + action: "reject" + errormsg: "invalid type: 'iterator (a: int, b: int, step: Positive): int{.inline, noSideEffect, gcsafe.}' for const" + line: 9 +""" +# Issue #16956: Error: not unused depending on unrelated code changes +# https://github.com/nim-lang/Nim/issues/16956 + +const f2 = case true + of true: countup[int] + of false: countdown[int] diff --git a/tests/generics/t21252.nim b/tests/generics/t21252.nim new file mode 100644 index 0000000000..5240280d72 --- /dev/null +++ b/tests/generics/t21252.nim @@ -0,0 +1,35 @@ +discard """ + output: '''done''' +""" +# Issue #21252: Compiler SIGSEGV when not instantiating generic proc correctly +# https://github.com/nim-lang/Nim/issues/21252 + +type + Addr = object + layerIdx: int + +type Msg0 = object + address: Addr + selSample: tuple[inArrays: seq[seq[float64]], target: seq[float64], gradientStrength: float64] + +type WeightUpdate = object + address: Addr + +proc workerThread[ + layer0StimulusWidth: static int + ]() = + discard + +proc z*[ + layer0StimulusWidth: static int, + nUnitsPerLayer: static seq[int], + targetLen: static int + ]() = + workerThread[layer0StimulusWidth]() + +when isMainModule: + const layer0StimulusWidth: int = 5*29 + const nUnitsPerLayer: seq[int] = @[50, 5] + const targetLen: int = 5 + z[layer0StimulusWidth, nUnitsPerLayer, targetLen]() + echo "done" diff --git a/tests/macros/t10902.nim b/tests/macros/t10902.nim new file mode 100644 index 0000000000..13a0f3f817 --- /dev/null +++ b/tests/macros/t10902.nim @@ -0,0 +1,31 @@ +discard """ + output: '''done''' +""" +# Issue #10902: cannot instantiate T when generating AST from macro +# https://github.com/nim-lang/Nim/issues/10902 + +import macros + +type + Base[T] = ref object + +macro genCloneProc(typeWithGenArg: untyped): untyped = + result = newProc( + ident "clone", [ + typeWithGenArg, + newIdentDefs( + ident "self", + typeWithGenArg, + ) + ], + newStmtList( + newNimNode(nnkDiscardStmt).add(newEmptyNode()) + ) + ) + let genericParamIdent = typeWithGenArg[1] + result[2] = newNimNode(nnkGenericParams) + result[2].add(newIdentDefs(genericParamIdent, newEmptyNode())) + +genCloneProc(Base[T]) + +echo "done" diff --git a/tests/macros/t13296.nim b/tests/macros/t13296.nim new file mode 100644 index 0000000000..e630f4dde9 --- /dev/null +++ b/tests/macros/t13296.nim @@ -0,0 +1,21 @@ +discard """ + output: '''done''' +""" +# Issue #13296: Error: not unused with a macro +# https://github.com/nim-lang/Nim/issues/13296 + +import macros +macro dType(body: untyped) = + if body.kind == nnkCall: + var typ = newNimNode(nnkStmtList) + typ.add quote do: + discard + elif body.kind == nnkTypeSection: + result = newStmtList( + body + ) + +dType: + echo "hi" + +echo "done" diff --git a/tests/macros/t9892.nim b/tests/macros/t9892.nim new file mode 100644 index 0000000000..f67e1d4c35 --- /dev/null +++ b/tests/macros/t9892.nim @@ -0,0 +1,16 @@ +discard """ + output: '''1''' +""" +# Issue #9892: Incorrect "Error: not unused" from else branch in macro +# https://github.com/nim-lang/Nim/issues/9892 + +import macros + +macro foo(x: typed): untyped = + result = newNimNode(nnkStmtListExpr) + if x.kind == nnkStmtListExpr: + result.add x + else: + result = x + +echo foo(1) diff --git a/tests/pragmas/t12424.nim b/tests/pragmas/t12424.nim new file mode 100644 index 0000000000..1a2e0ebdcf --- /dev/null +++ b/tests/pragmas/t12424.nim @@ -0,0 +1,8 @@ +discard """ + nimout: '''t12424.nim(8, 10) Warning: This is a test warning from user code [User]''' +""" +# Issue #12424: Warning and Hint Pragmas do not print to console when declared from a std lib module +# https://github.com/nim-lang/Nim/issues/12424 +# This test verifies that warning pragmas in user code work correctly. + +{.warning: "This is a test warning from user code".} diff --git a/tests/typerel/t22842.nim b/tests/typerel/t22842.nim new file mode 100644 index 0000000000..917aee875f --- /dev/null +++ b/tests/typerel/t22842.nim @@ -0,0 +1,11 @@ +discard """ + output: '''done''' +""" +# Issue #22842: internal error: getTypeDescAux(tyAnything) with auto in proc type +# https://github.com/nim-lang/Nim/issues/22842 + +proc register(cb: proc (e: auto): void) = discard + +register(proc (e: int) = echo e) + +echo "done"