summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorBung <crc32@qq.com>2023-01-13 06:36:13 -0800
committerGitHub <noreply@github.com>2023-01-13 15:36:13 +0100
commit5f41be3b4503a76fb68018c3ff5b05b35d6d68c1 (patch)
treefa89c4ce02a3911924d8a060eacffa086d4c25e6
parent1e52423774e81f71d10a712575fd65231705362e (diff)
downloadNim-5f41be3b4503a76fb68018c3ff5b05b35d6d68c1.tar.gz
fix #20253 (#21174)
* fix #20253

* change NimbleStableCommit

* Update koch.nim

Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
-rw-r--r--compiler/sempass2.nim5
-rw-r--r--tests/misc/t20253.nim10
2 files changed, 14 insertions, 1 deletions
diff --git a/compiler/sempass2.nim b/compiler/sempass2.nim
index f13d8d8d4..747540c78 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 000000000..d47c36c55
--- /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
='#n153'>153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218