summary refs log tree commit diff stats
path: root/compiler
diff options
context:
space:
mode:
Diffstat (limited to 'compiler')
-rw-r--r--compiler/extccomp.nim2
-rw-r--r--compiler/sem.nim7
-rw-r--r--compiler/semexprs.nim2
-rw-r--r--compiler/semstmts.nim19
-rw-r--r--compiler/semtempl.nim5
-rw-r--r--compiler/semtypes.nim15
-rw-r--r--compiler/vm.nim2
7 files changed, 29 insertions, 23 deletions
diff --git a/compiler/extccomp.nim b/compiler/extccomp.nim
index ae2971b65..473911b84 100644
--- a/compiler/extccomp.nim
+++ b/compiler/extccomp.nim
@@ -759,7 +759,7 @@ proc getLinkCmd(conf: ConfigRef; output: AbsoluteFile,
 template getLinkCmd(conf: ConfigRef; output: AbsoluteFile, objfiles: string): string =
   getLinkCmd(conf, output, objfiles, optGenDynLib in conf.globalOptions)
 
-template tryExceptOSErrorMessage(conf: ConfigRef; errorPrefix: string = "", body: untyped): typed =
+template tryExceptOSErrorMessage(conf: ConfigRef; errorPrefix: string = "", body: untyped) =
   try:
     body
   except OSError:
diff --git a/compiler/sem.nim b/compiler/sem.nim
index d4e944028..a4e6a427b 100644
--- a/compiler/sem.nim
+++ b/compiler/sem.nim
@@ -407,12 +407,11 @@ proc semAfterMacroCall(c: PContext, call, macroResult: PNode,
   else:
     case s.typ.sons[0].kind
     of tyUntyped:
-      # BUGFIX: we cannot expect a type here, because module aliases would not
-      # work then (see the ``tmodulealias`` test)
-      # semExprWithType(c, result)
+      # Not expecting a type here allows templates like in ``tmodulealias.in``.
       result = semExpr(c, result, flags)
     of tyTyped:
-      result = semStmt(c, result, flags)
+      # More restrictive version.
+      result = semExprWithType(c, result, flags)
     of tyTypeDesc:
       if result.kind == nkStmtList: result.kind = nkStmtListType
       var typ = semTypeNode(c, result, nil)
diff --git a/compiler/semexprs.nim b/compiler/semexprs.nim
index 6261efaaa..767a13f3e 100644
--- a/compiler/semexprs.nim
+++ b/compiler/semexprs.nim
@@ -1985,7 +1985,7 @@ proc semQuoteAst(c: PContext, n: PNode): PNode =
 
   if ids.len > 0:
     dummyTemplate.sons[paramsPos] = newNodeI(nkFormalParams, n.info)
-    dummyTemplate[paramsPos].add getSysSym(c.graph, n.info, "typed").newSymNode # return type
+    dummyTemplate[paramsPos].add getSysSym(c.graph, n.info, "untyped").newSymNode # return type
     ids.add getSysSym(c.graph, n.info, "untyped").newSymNode # params type
     ids.add c.graph.emptyNode # no default value
     dummyTemplate[paramsPos].add newNode(nkIdentDefs, n.info, ids)
diff --git a/compiler/semstmts.nim b/compiler/semstmts.nim
index 7f0910429..be7d9a1bf 100644
--- a/compiler/semstmts.nim
+++ b/compiler/semstmts.nim
@@ -1356,7 +1356,7 @@ proc semBorrow(c: PContext, n: PNode, s: PSym) =
     localError(c.config, n.info, errNoSymbolToBorrowFromFound)
 
 proc addResult(c: PContext, t: PType, info: TLineInfo, owner: TSymKind) =
-  if t != nil:
+  if owner == skMacro or t != nil:
     var s = newSym(skResult, getIdent(c.cache, "result"), getCurrOwner(c), info)
     s.typ = t
     incl(s.flags, sfUsed)
@@ -1550,17 +1550,17 @@ proc activate(c: PContext, n: PNode) =
       discard
 
 proc maybeAddResult(c: PContext, s: PSym, n: PNode) =
-  if s.typ.sons[0] != nil and not isInlineIterator(s):
+  if s.kind == skMacro:
     let resultType =
-      if s.kind == skMacro:
-        if s.typ.sons[0].kind == tyTypeDesc:
-          s.typ.sons[0]
-        else:
-          sysTypeFromName(c.graph, n.info, "NimNode")
-      else:
+      if s.typ.sons[0] != nil and s.typ.sons[0].kind == tyTypeDesc:
         s.typ.sons[0]
+      else:
+        sysTypeFromName(c.graph, n.info, "NimNode")
     addResult(c, resultType, n.info, s.kind)
     addResultNode(c, n)
+  elif s.typ.sons[0] != nil and not isInlineIterator(s):
+    addResult(c, s.typ.sons[0], n.info, s.kind)
+    addResultNode(c, n)
 
 proc canonType(c: PContext, t: PType): PType =
   if t.kind == tySequence:
@@ -1888,7 +1888,7 @@ proc semProcAux(c: PContext, n: PNode, kind: TSymKind,
           # context as it may even be evaluated in 'system.compiles':
           trackProc(c, s, s.ast[bodyPos])
       else:
-        if s.typ.sons[0] != nil and kind != skIterator:
+        if (s.typ.sons[0] != nil and kind != skIterator) or kind == skMacro:
           addDecl(c, newSym(skUnknown, getIdent(c.cache, "result"), nil, n.info))
 
         openScope(c)
@@ -2015,7 +2015,6 @@ proc semMacroDef(c: PContext, n: PNode): PNode =
     let param = t.n.sons[i].sym
     if param.typ.kind != tyUntyped: allUntyped = false
   if allUntyped: incl(s.flags, sfAllUntyped)
-  if t.sons[0] == nil: localError(c.config, n.info, "macro needs a return type")
   if n.sons[bodyPos].kind == nkEmpty:
     localError(c.config, n.info, errImplOfXexpected % s.name.s)
 
diff --git a/compiler/semtempl.nim b/compiler/semtempl.nim
index 2cbbd7b54..7a56f8c45 100644
--- a/compiler/semtempl.nim
+++ b/compiler/semtempl.nim
@@ -606,11 +606,6 @@ proc semTemplateDef(c: PContext, n: PNode): PNode =
       if n.sons[genericParamsPos].kind == nkEmpty:
         # we have a list of implicit type parameters:
         n.sons[genericParamsPos] = gp
-    # no explicit return type? -> use tyTyped
-    if n.sons[paramsPos].sons[0].kind == nkEmpty:
-      # use ``stmt`` as implicit result type
-      s.typ.sons[0] = newTypeS(tyTyped, c)
-      s.typ.n.sons[0] = newNodeIT(nkType, n.info, s.typ.sons[0])
   else:
     s.typ = newTypeS(tyProc, c)
     # XXX why do we need tyTyped as a return type again?
diff --git a/compiler/semtypes.nim b/compiler/semtypes.nim
index 86cb0f35b..dd9aea0f8 100644
--- a/compiler/semtypes.nim
+++ b/compiler/semtypes.nim
@@ -855,6 +855,7 @@ proc findEnforcedStaticType(t: PType): PType =
   # This handles types such as `static[T] and Foo`,
   # which are subset of `static[T]`, hence they could
   # be treated in the same way
+  if t == nil: return nil
   if t.kind == tyStatic: return t
   if t.kind == tyAnd:
     for s in t.sons:
@@ -868,7 +869,7 @@ proc addParamOrResult(c: PContext, param: PSym, kind: TSymKind) =
       var a = copySym(param)
       a.typ = staticType.base
       addDecl(c, a)
-    elif param.typ.kind == tyTypeDesc:
+    elif param.typ != nil and param.typ.kind == tyTypeDesc:
       addDecl(c, param)
     else:
       # within a macro, every param has the type NimNode!
@@ -1194,6 +1195,18 @@ proc semProcTypeNode(c: PContext, n, genericParams: PNode,
   if n.sons[0].kind != nkEmpty:
     r = semTypeNode(c, n.sons[0], nil)
 
+  if r != nil and kind in {skMacro, skTemplate} and r.kind == tyTyped:
+    # XXX: To implement the propesed change in the warning, just
+    # delete this entire if block. The rest is (at least at time of
+    # writing this comment) already implemented.
+    let info = n.sons[0].info
+    const msg = "`typed` will change its meaning in future versions of Nim. " &
+                "`void` or no return type declaration at all has the same " &
+                "meaning as the current meaning of `typed` as return type " &
+                "declaration."
+    message(c.config, info, warnDeprecated, msg)
+    r = nil
+
   if r != nil:
     # turn explicit 'void' return type into 'nil' because the rest of the
     # compiler only checks for 'nil':
diff --git a/compiler/vm.nim b/compiler/vm.nim
index 6fc2626f7..aa8203a92 100644
--- a/compiler/vm.nim
+++ b/compiler/vm.nim
@@ -1104,7 +1104,7 @@ proc rawExecute(c: PCtx, start: int, tos: PStackFrame): TFullReg =
         #echo "new pc ", newPc, " calling: ", prc.name.s
         var newFrame = PStackFrame(prc: prc, comesFrom: pc, next: tos)
         newSeq(newFrame.slots, prc.offset+ord(isClosure))
-        if not isEmptyType(prc.typ.sons[0]) or prc.kind == skMacro:
+        if not isEmptyType(prc.typ.sons[0]):
           putIntoReg(newFrame.slots[0], getNullValue(prc.typ.sons[0], prc.info, c.config))
         for i in 1 .. rc-1:
           newFrame.slots[i] = regs[rb+i]
amp;id=d9fbe9c1ca8919f0dba5d5b606b1d5609d3ee73a'>d9fbe9c1 ^
77d5b5d6 ^
d9fbe9c1 ^
2c7e84c2 ^
d9fbe9c1 ^

bc643692 ^
ce87c19e ^
d9fbe9c1 ^
bc643692 ^
ce87c19e ^
d9fbe9c1 ^


ce87c19e ^




d9fbe9c1 ^
ce87c19e ^


d9fbe9c1 ^
ce87c19e ^
d9fbe9c1 ^
ce87c19e ^






d9fbe9c1 ^
ce87c19e ^

d9fbe9c1 ^


d9fbe9c1 ^

9d670bb5 ^
0b45be43 ^
a91c1c2a ^
77d5b5d6 ^
5497090a ^
768bdb4d ^
ce87c19e ^


768bdb4d ^
bc643692 ^

768bdb4d ^
ce87c19e ^




768bdb4d ^

ce87c19e ^
768bdb4d ^

a91c1c2a ^
77d5b5d6 ^
5497090a ^

ce87c19e ^
bc643692 ^

768bdb4d ^
ce87c19e ^





768bdb4d ^

ce87c19e ^
768bdb4d ^


77d5b5d6 ^
768bdb4d ^

bc643692 ^
768bdb4d ^
ce87c19e ^
768bdb4d ^
ce87c19e ^


768bdb4d ^
ce87c19e ^

768bdb4d ^
ce87c19e ^
768bdb4d ^
bc643692 ^
768bdb4d ^
bc643692 ^
768bdb4d ^
ce87c19e ^




768bdb4d ^

ce87c19e ^

768bdb4d ^


8e41a2b8 ^

ce87c19e ^






8e41a2b8 ^

768bdb4d ^

e0053bcb ^

77d5b5d6 ^
e0053bcb ^








bc643692 ^








ce87c19e ^

e0053bcb ^


bc643692 ^
e0053bcb ^


8e41a2b8 ^
768bdb4d ^














768bdb4d ^

9d670bb5 ^

0b45be43 ^
9d670bb5 ^

5497090a ^



9d670bb5 ^

4071055a ^

9d670bb5 ^
77d5b5d6 ^
9d670bb5 ^
4071055a ^
ce87c19e ^


9d670bb5 ^
bd5ae9d8 ^
ce87c19e ^









bc643692 ^

ce87c19e ^



ce87c19e ^


9d670bb5 ^

5497090a ^
4071055a ^
9d670bb5 ^
77d5b5d6 ^
9d670bb5 ^
4071055a ^
ce87c19e ^
9d670bb5 ^
ce87c19e ^

bc643692 ^
01aeedd9 ^

ce87c19e ^

bc643692 ^
9d670bb5 ^
971e710d ^
ce87c19e ^

bc643692 ^
5d6d9110 ^

ce87c19e ^

971e710d ^
ce87c19e ^
bc643692 ^
971e710d ^
ce87c19e ^
9d670bb5 ^
4071055a ^
ce87c19e ^

4071055a ^
ce87c19e ^


bc643692 ^
4071055a ^

ce87c19e ^




bc643692 ^
4071055a ^
ce87c19e ^
9d670bb5 ^

5497090a ^
4071055a ^
9d670bb5 ^
77d5b5d6 ^
9d670bb5 ^
4071055a ^
ce87c19e ^
9d670bb5 ^
ce87c19e ^

bc643692 ^
01aeedd9 ^

ce87c19e ^

bc643692 ^
9d670bb5 ^
971e710d ^
ce87c19e ^

971e710d ^
ce87c19e ^
bc643692 ^
971e710d ^
ce87c19e ^
9d670bb5 ^
4071055a ^
ce87c19e ^




bc643692 ^
4071055a ^

ce87c19e ^




bc643692 ^
4071055a ^
ce87c19e ^
9d670bb5 ^


4071055a ^
9d670bb5 ^
77d5b5d6 ^
9d670bb5 ^

4071055a ^
ce87c19e ^
4071055a ^
ce87c19e ^

4071055a ^
ce87c19e ^
4071055a ^
ce87c19e ^

9d670bb5 ^


bc643692 ^
9d670bb5 ^
bc643692 ^
5497090a ^
9d670bb5 ^
5497090a ^
5497090a ^
bc643692 ^
9d670bb5 ^


bc643692 ^
5497090a ^
9d670bb5 ^
5497090a ^

bc643692 ^
9d670bb5 ^


bc643692 ^
5497090a ^
9d670bb5 ^
5497090a ^

bc643692 ^
9d670bb5 ^


bc643692 ^
5497090a ^
9d670bb5 ^
5497090a ^

bc643692 ^
9d670bb5 ^


bc643692 ^
5497090a ^
9d670bb5 ^
5497090a ^

bc643692 ^
9d670bb5 ^


bc643692 ^
5497090a ^
9d670bb5 ^
5497090a ^

bc643692 ^
9d670bb5 ^


bc643692 ^
5497090a ^
9d670bb5 ^
5497090a ^

bc643692 ^
9d670bb5 ^







01aeedd9 ^

bc643692 ^
01aeedd9 ^
bc643692 ^
5497090a ^
01aeedd9 ^
5497090a ^

bc643692 ^
01aeedd9 ^


bc643692 ^
5497090a ^
01aeedd9 ^
5497090a ^

bc643692 ^
01aeedd9 ^









bc643692 ^
01aeedd9 ^
bc643692 ^
5497090a ^
01aeedd9 ^
5497090a ^

bc643692 ^
01aeedd9 ^

bc643692 ^
5497090a ^

01aeedd9 ^
4071055a ^


01aeedd9 ^



bc643692 ^
01aeedd9 ^
bc643692 ^
5497090a ^
01aeedd9 ^
5497090a ^

bc643692 ^
01aeedd9 ^

bc643692 ^

5497090a ^

01aeedd9 ^
4071055a ^


971e710d ^



bc643692 ^
971e710d ^
bc643692 ^
5497090a ^
971e710d ^
5497090a ^

bc643692 ^
971e710d ^

bc643692 ^

5497090a ^

971e710d ^



01aeedd9 ^

1abde57f ^

77d5b5d6 ^
1abde57f ^

ce87c19e ^
ce87c19e ^
ce87c19e ^
ce87c19e ^
ce87c19e ^



ce87c19e ^


1abde57f ^


bc643692 ^
1abde57f ^
e0053bcb ^
1abde57f ^
ce87c19e ^







1abde57f ^















1abde57f ^

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
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
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614