@@ -113,18 +113,18 @@ reject THasNotNils(a: notNilRef, b: nilRef, c: nilRef) # `b` shouldn't be n
113
113
reject THasNotNils (b: notNilRef, c: notNilRef) # there is a missing not nil field
114
114
reject THasNotNils () # again, missing fields
115
115
accept THasNotNils (a: notNilRef, b: notNilRef) # it's OK to omit a non-mandatory field
116
- reject default (THasNotNils )
117
- reject userDefinedDefault (THasNotNils )
116
+ # produces only warning: reject default(THasNotNils)
117
+ # produces only warning: reject userDefinedDefault(THasNotNils)
118
118
119
- reject default (TRefObjNotNil )
120
- reject userDefinedDefault (TRefObjNotNil )
121
- reject genericDefault (TRefObjNotNil )
119
+ # produces only warning: reject default(TRefObjNotNil)
120
+ # produces only warning: reject userDefinedDefault(TRefObjNotNil)
121
+ # produces only warning: reject genericDefault(TRefObjNotNil)
122
122
123
123
# missing not nils in base
124
124
reject TBaseHasNotNils ()
125
- reject default (TBaseHasNotNils )
126
- reject userDefinedDefault (TBaseHasNotNils )
127
- reject genericDefault (TBaseHasNotNils )
125
+ # produces only warning: reject default(TBaseHasNotNils)
126
+ # produces only warning: reject userDefinedDefault(TBaseHasNotNils)
127
+ # produces only warning: reject genericDefault(TBaseHasNotNils)
128
128
129
129
# once you take care of them, it's ok
130
130
accept TBaseHasNotNils (a: notNilRef, b: notNilRef, choice: D)
@@ -163,8 +163,8 @@ accept((ref PartialRequiresInit)(a: 20))
163
163
reject ((ref PartialRequiresInit )(b: " x" ))
164
164
reject ((ref PartialRequiresInit )())
165
165
166
- reject default (PartialRequiresInit )
167
- reject userDefinedDefault (PartialRequiresInit )
166
+ # produces only warning: reject default(PartialRequiresInit)
167
+ # produces only warning: reject userDefinedDefault(PartialRequiresInit)
168
168
reject:
169
169
var obj: PartialRequiresInit
170
170
@@ -181,8 +181,8 @@ reject((ref FullRequiresInit)(a: 10))
181
181
reject ((ref FullRequiresInit )(b: 20 ))
182
182
reject ((ref FullRequiresInit )())
183
183
184
- reject default (FullRequiresInit )
185
- reject userDefinedDefault (FullRequiresInit )
184
+ # produces only warning: reject default(FullRequiresInit)
185
+ # produces only warning: reject userDefinedDefault(FullRequiresInit)
186
186
reject:
187
187
var obj: FullRequiresInit
188
188
@@ -192,8 +192,8 @@ reject FullRequiresInitWithParent(a: notNilRef, b: nil, c: nil, e: 10, d: 20) #
192
192
reject FullRequiresInitWithParent (a: notNilRef, b: notNilRef, e: 10 , d: 20 ) # c should not be missing
193
193
reject FullRequiresInitWithParent (a: notNilRef, b: notNilRef, c: nil , e: 10 ) # d should not be missing
194
194
reject FullRequiresInitWithParent ()
195
- reject default (FullRequiresInitWithParent )
196
- reject userDefinedDefault (FullRequiresInitWithParent )
195
+ # produces only warning: reject default(FullRequiresInitWithParent)
196
+ # produces only warning: reject userDefinedDefault(FullRequiresInitWithParent)
197
197
reject:
198
198
var obj: FullRequiresInitWithParent
199
199
@@ -203,28 +203,36 @@ accept default(TNestedChoices)
203
203
accept:
204
204
var obj: TNestedChoices
205
205
206
+ #[ # produces only warning:
206
207
reject:
207
208
# This proc is illegal, because it tries to produce
208
209
# a default object of a type that requires initialization:
209
210
proc defaultHasNotNils: THasNotNils =
210
211
discard
212
+ #]#
211
213
214
+ #[ # produces only warning:
212
215
reject:
213
216
# You cannot cheat by using the result variable to specify
214
217
# only some of the fields
215
218
proc invalidPartialTHasNotNils: THasNotNils =
216
219
result.c = nilRef
220
+ #]#
217
221
222
+ #[ # produces only warning:
218
223
reject:
219
224
# The same applies for requiresInit types
220
225
proc invalidPartialRequiersInit: PartialRequiresInit =
221
226
result.b = "x"
227
+ #]#
222
228
229
+ #[ # produces only warning:
223
230
# All code paths must return a value when the result requires initialization:
224
231
reject:
225
232
proc ifWithoutAnElse: THasNotNils =
226
233
if stdin.readLine == "":
227
234
return THasNotNils(a: notNilRef, b: notNilRef, c: nilRef)
235
+ #]#
228
236
229
237
accept:
230
238
# All code paths must return a value when the result requires initialization:
@@ -234,6 +242,7 @@ accept:
234
242
else :
235
243
return THasNotNIls (a: notNilRef, b: notNilRef)
236
244
245
+ #[ # produces only warning:
237
246
reject:
238
247
proc caseWithoutAllCasesCovered: FullRequiresInit =
239
248
# Please note that these is no else branch here:
@@ -242,6 +251,7 @@ reject:
242
251
return FullRequiresInit(a: 10, b: 20)
243
252
of "y":
244
253
return FullRequiresInit(a: 30, b: 40)
254
+ #]#
245
255
246
256
accept:
247
257
proc wellFormedCase : FullRequiresInit =
@@ -276,18 +286,24 @@ block:
276
286
var one = legalSeq[0 ]
277
287
var twoAgain = legalSeq.pop
278
288
289
+ #[ # produces only warning:
279
290
# It's not possible to tell the sequence to create elements
280
291
# for us though:
281
292
reject:
282
293
var illegalSeq = newSeq[IllegalToConstruct](10)
294
+ #]#
283
295
296
+ #[ # produces only warning:
284
297
reject:
285
298
var illegalSeq: seq[IllegalToConstruct]
286
299
newSeq(illegalSeq, 10)
300
+ #]#
287
301
302
+ #[ # produces only warning:
288
303
reject:
289
304
var illegalSeq: seq[IllegalToConstruct]
290
305
illegalSeq.setLen 10
306
+ #]#
291
307
292
308
# You can still use newSeqOfCap to write efficient code:
293
309
var anotherLegalSequence = newSeqOfCap [IllegalToConstruct ](10 )
@@ -363,8 +379,10 @@ block:
363
379
reject:
364
380
var x: IllegalPair
365
381
382
+ #[ # produces only warning:
366
383
reject:
367
384
var s = newSeq[IllegalPair](10)
385
+ #]#
368
386
369
387
# Specific issues:
370
388
#
0 commit comments