tprecedence.nim 818 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. discard """
  2. output: '''holla
  3. true
  4. defabc 4
  5. 0'''
  6. """
  7. # Test top level semicolon works properly:
  8. import os; echo "holla"
  9. # Test the new predence rules
  10. proc `\+` (x, y: int): int = result = x + y
  11. proc `\*` (x, y: int): int = result = x * y
  12. echo 5 \+ 1 \* 9 == 6*9
  13. proc foo[S, T](x: S, y: T): T = x & y
  14. proc bar[T](x: T): T = x
  15. echo "def".foo[:string, string]("abc"), " ", 4.bar[:int]
  16. # bug #9574
  17. proc isFalse(a: int): bool = false
  18. assert not isFalse(3)
  19. # bug #9633
  20. type
  21. MyField = object
  22. b: seq[string]
  23. MyObject = object
  24. f: MyField
  25. proc getX(x: MyObject): lent MyField {.inline.} =
  26. x.f
  27. let a = MyObject()
  28. echo a.getX.b.len
  29. # bug #10458
  30. template t(x: untyped): untyped = "x"
  31. let
  32. aaa = t 2 + 4
  33. ccc = t (1, 1) + 6
  34. ddd = t [0, 1, 2] + 5
  35. # bug #10896
  36. const
  37. test =
  38. proc(): int = 1