summary refs log tree commit diff stats
path: root/tests/template
diff options
context:
space:
mode:
authormetagn <metagngn@gmail.com>2023-06-12 07:34:34 +0300
committerGitHub <noreply@github.com>2023-06-12 06:34:34 +0200
commit71801c2b8f7eb080421aae9140cd15c5fcc34efd (patch)
tree4e912a2133f4825a830b2a2bed55385103a8b1c0 /tests/template
parente0ad71a912361d994b1d7b052d0153f7f5528a63 (diff)
downloadNim-71801c2b8f7eb080421aae9140cd15c5fcc34efd.tar.gz
fix dot calls with resolved symbols in templates (#22076)
* fix dot calls with resolved symbols in templates

* make old code work

* fix custom number literals test

* remove leftover debug marker

* enable "bug 9" test too

* fix renderer, add test for #7085
Diffstat (limited to 'tests/template')
-rw-r--r--tests/template/mdotcall.nim22
-rw-r--r--tests/template/tdotcall.nim10
2 files changed, 32 insertions, 0 deletions
diff --git a/tests/template/mdotcall.nim b/tests/template/mdotcall.nim
new file mode 100644
index 000000000..38a6ccae0
--- /dev/null
+++ b/tests/template/mdotcall.nim
@@ -0,0 +1,22 @@
+# issue #20073
+
+type Foo = object
+proc foo(f: Foo) = discard
+
+template works*() =
+  var f: Foo
+  foo(f)
+
+template boom*() =
+  var f: Foo
+  f.foo() # Error: attempting to call undeclared routine: 'foo'
+  f.foo # Error: undeclared field: 'foo' for type a.Foo
+
+# issue #7085
+
+proc bar(a: string): string =
+  return a & "bar"
+
+template baz*(a: string): string =
+  var b = a.bar()
+  b
diff --git a/tests/template/tdotcall.nim b/tests/template/tdotcall.nim
new file mode 100644
index 000000000..abcbc8bd5
--- /dev/null
+++ b/tests/template/tdotcall.nim
@@ -0,0 +1,10 @@
+import mdotcall
+
+# issue #20073
+works()
+boom()
+
+# issue #7085
+doAssert baz("hello") == "hellobar"
+doAssert baz"hello" == "hellobar"
+doAssert "hello".baz == "hellobar"