mdotcall.nim 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. # issue #20073
  2. type Foo = object
  3. proc foo(f: Foo) = discard
  4. template works*() =
  5. var f: Foo
  6. foo(f)
  7. template boom*() =
  8. var f: Foo
  9. f.foo() # Error: attempting to call undeclared routine: 'foo'
  10. f.foo # Error: undeclared field: 'foo' for type a.Foo
  11. # issue #7085
  12. proc bar(a: string): string =
  13. return a & "bar"
  14. template baz*(a: string): string =
  15. var b = a.bar()
  16. b
  17. # issue #7223
  18. import mdotcall2
  19. type
  20. Bytes* = seq[byte]
  21. BytesRange* = object
  22. bytes*: Bytes
  23. ibegin*, iend*: int
  24. proc privateProc(r: BytesRange): int = r.ibegin
  25. template rangeBeginAddr*(r: BytesRange): pointer =
  26. r.bytes.baseAddr.shift(r.privateProc)
  27. # issue #11733
  28. type ObjA* = object
  29. proc foo2(o: var ObjA) = discard
  30. proc bar2(o: var ObjA, arg: Natural) = discard
  31. template publicTemplateObjSyntax*(o: var ObjA, arg: Natural, doStuff: untyped) =
  32. o.foo2()
  33. doStuff
  34. o.bar2(arg)
  35. # issue #15246
  36. import os
  37. template sourceBaseName*(): string =
  38. bind splitFile
  39. instantiationInfo().filename.splitFile().name
  40. # issue #12683
  41. import unicode
  42. template toRune(s: string): Rune = s.runeAt(0)
  43. proc heh*[T](x: Slice[T], chars: string) = discard chars.toRune
  44. # issue #7889
  45. from streams import newStringStream, readData, writeData
  46. template bindmeTemplate*(): untyped =
  47. var tst = "sometext"
  48. var ss = newStringStream("anothertext")
  49. ss.writeData(tst[0].addr, 2)
  50. discard ss.readData(tst[0].addr, 2) # <= comment this out to make compilation successful
  51. from macros import quote, newIdentNode
  52. macro bindmeQuote*(): untyped =
  53. quote do:
  54. var tst = "sometext"
  55. var ss = newStringStream("anothertext")
  56. ss.writeData(tst[0].addr, 2)
  57. discard ss.readData(tst[0].addr, 2) # <= comment this out to make compilation successful