From 5f41be3b4503a76fb68018c3ff5b05b35d6d68c1 Mon Sep 17 00:00:00 2001 From: Bung Date: Fri, 13 Jan 2023 06:36:13 -0800 Subject: [PATCH] fix #20253 (#21174) * fix #20253 * change NimbleStableCommit * Update koch.nim Co-authored-by: Andreas Rumpf --- compiler/sempass2.nim | 5 ++++- tests/misc/t20253.nim | 10 ++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 tests/misc/t20253.nim diff --git a/compiler/sempass2.nim b/compiler/sempass2.nim index f13d8d8d4b..747540c784 100644 --- a/compiler/sempass2.nim +++ b/compiler/sempass2.nim @@ -1488,7 +1488,10 @@ proc trackProc*(c: PContext; s: PSym, body: PNode) = s.kind in {skProc, skFunc, skConverter, skMethod} and s.magic == mNone: var res = s.ast[resultPos].sym # get result symbol if res.id notin t.init: - message(g.config, body.info, warnProveInit, "result") + if tfRequiresInit in s.typ[0].flags: + localError(g.config, body.info, "'$1' requires explicit initialization" % "result") + else: + message(g.config, body.info, warnProveInit, "result") let p = s.ast[pragmasPos] let raisesSpec = effectSpec(p, wRaises) if not isNil(raisesSpec): diff --git a/tests/misc/t20253.nim b/tests/misc/t20253.nim new file mode 100644 index 0000000000..d47c36c55d --- /dev/null +++ b/tests/misc/t20253.nim @@ -0,0 +1,10 @@ +discard """ + errormsg: "'result' requires explicit initialization" + line: 10 +""" + +type Meow {.requiresInit.} = object + init: bool + +proc initMeow(): Meow = + discard