tprecedence.nim 962 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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
  39. # bug #8759
  40. block:
  41. template `=>`(a, b): untyped = (a, b)
  42. template `+=`(a, b): untyped = a * b
  43. doAssert ("abc" => 3 += 5) == ("abc", 15)