summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorSaem Ghani <saemghani+github@gmail.com>2021-03-21 16:33:37 -0700
committerGitHub <noreply@github.com>2021-03-22 00:33:37 +0100
commit23fd0984283fe94108dea5d569450f5e0564c59d (patch)
treeeb27f3cbdedc104223b190953a5cc1e1afc051ea
parent5bed7d282ad043d945225fe72adb654d49b4f2ee (diff)
downloadNim-23fd0984283fe94108dea5d569450f5e0564c59d.tar.gz
Fixes #17433; gensym callDef return in templ body (#17445)
-rw-r--r--compiler/semtempl.nim2
-rw-r--r--tests/template/t17433.nim16
2 files changed, 17 insertions, 1 deletions
diff --git a/compiler/semtempl.nim b/compiler/semtempl.nim
index 568873269..4bb9f3e6b 100644
--- a/compiler/semtempl.nim
+++ b/compiler/semtempl.nim
@@ -435,8 +435,8 @@ proc semTemplBody(c: var TemplCtx, n: PNode): PNode =
   of nkLetSection: semTemplSomeDecl(c, n, skLet)
   of nkFormalParams:
     checkMinSonsLen(n, 1, c.c.config)
-    n[0] = semTemplBody(c, n[0])
     semTemplSomeDecl(c, n, skParam, 1)
+    n[0] = semTemplBody(c, n[0])
   of nkConstSection:
     for i in 0..<n.len:
       var a = n[i]
diff --git a/tests/template/t17433.nim b/tests/template/t17433.nim
new file mode 100644
index 000000000..121f3c471
--- /dev/null
+++ b/tests/template/t17433.nim
@@ -0,0 +1,16 @@
+# Inside template bodies, ensure return types referencing a param are replaced.
+# This helps guarantee that return parameter analysis happens after argument
+# analysis.
+ 
+# bug #17433
+
+from std/macros import expandMacros
+
+proc bar(a: typedesc): a = default(a)
+assert bar(float) == 0.0
+assert bar(string) == ""
+
+template main =
+  proc baz(a: typedesc): a = default(a)
+  assert baz(float) == 0.0
+main()