talias.nim 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. # Test the alias analysis
  2. type
  3. TAnalysisResult* = enum
  4. arNo, arMaybe, arYes
  5. proc isPartOf*[S, T](a: S, b: T): TAnalysisResult {.
  6. magic: "IsPartOf", noSideEffect.}
  7. ## not yet exported properly.
  8. template compileTimeAssert(cond) =
  9. when not cond:
  10. {.compile: "is false: " & astToStr(cond).}
  11. template `<|` (a, b) =
  12. compileTimeAssert isPartOf(a, b) == arYes
  13. template `!<|` (a, b) =
  14. compileTimeAssert isPartOf(a, b) == arNo
  15. template `?<|` (a, b) =
  16. compileTimeAssert isPartOf(a, b) == arMaybe
  17. type
  18. TA {.inheritable.} = object
  19. TC = object of TA
  20. arr: array[0..3, int]
  21. le, ri: ref TC
  22. f: string
  23. c: char
  24. se: seq[TA]
  25. proc p(param1, param2: TC, param3: var TC): TC =
  26. var
  27. local: TC
  28. plocal: ptr TC
  29. plocal2: ptr TA
  30. local.arr <| local
  31. local.arr[0] <| local
  32. local.arr[2] !<| local.arr[1]
  33. plocal2[] ?<| local
  34. param1 ?<| param2
  35. local ?<| param3
  36. local.arr[0] !<| param1
  37. local.arr !<| param1
  38. local.le[] ?<| param1
  39. param1 !<| local.arr[0]
  40. param1 !<| local.arr
  41. param1 ?<| local.le[]
  42. result !<| local
  43. result <| result
  44. var
  45. a, b: int
  46. x: TC
  47. a <| a
  48. a !<| b
  49. discard p(x, x, x)