t23657.nim 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. discard """
  2. targets: "cpp"
  3. cmd: "nim cpp -r $file"
  4. output: '''
  5. 1.0
  6. 1.0
  7. '''
  8. """
  9. {.emit:"""/*TYPESECTION*/
  10. struct Point {
  11. float x, y, z;
  12. Point(float x, float y, float z): x(x), y(y), z(z) {}
  13. Point() = default;
  14. };
  15. struct Direction {
  16. float x, y, z;
  17. Direction(float x, float y, float z): x(x), y(y), z(z) {}
  18. Direction() = default;
  19. };
  20. struct Axis {
  21. Point origin;
  22. Direction direction;
  23. Axis(Point origin, Direction direction): origin(origin), direction(direction) {}
  24. Axis() = default;
  25. };
  26. """.}
  27. type
  28. Point {.importcpp.} = object
  29. x, y, z: float
  30. Direction {.importcpp.} = object
  31. x, y, z: float
  32. Axis {.importcpp.} = object
  33. origin: Point
  34. direction: Direction
  35. proc makeAxis(origin: Point, direction: Direction): Axis {. constructor, importcpp:"Axis(@)".}
  36. proc makePoint(x, y, z: float): Point {. constructor, importcpp:"Point(@)".}
  37. proc makeDirection(x, y, z: float): Direction {. constructor, importcpp:"Direction(@)".}
  38. var axis1 = makeAxis(Point(x: 1.0, y: 2.0, z: 3.0), Direction(x: 4.0, y: 5.0, z: 6.0)) #Triggers the error (T1)
  39. var axis2Ctor = makeAxis(makePoint(1.0, 2.0, 3.0), makeDirection(4.0, 5.0, 6.0)) #Do not triggers
  40. proc main() = #Do not triggers as Tx are inside the body
  41. let test = makeAxis(Point(x: 1.0, y: 2.0, z: 3.0), Direction(x: 4.0, y: 5.0, z: 6.0))
  42. echo test.origin.x
  43. main()
  44. echo $axis1.origin.x #Make sures it's init