diff options
author | Juan M Gómez <info@jmgomez.me> | 2024-06-02 14:15:03 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-06-02 15:15:03 +0200 |
commit | cb0ebecb2045143f71b7be40b853672a987fa4d1 (patch) | |
tree | 8a056febed7c21afa12af9e7d4282210cf1761e8 /tests/cpp/t23657.nim | |
parent | 08f1eac8ac46baccd1701715feb8aca7b00e0be7 (diff) | |
download | Nim-cb0ebecb2045143f71b7be40b853672a987fa4d1.tar.gz |
#Fixes #23657 C++ compilation fails with: 'T1_' was not declared in t… (#23666)
…his scope
Diffstat (limited to 'tests/cpp/t23657.nim')
-rw-r--r-- | tests/cpp/t23657.nim | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/tests/cpp/t23657.nim b/tests/cpp/t23657.nim new file mode 100644 index 000000000..63deb7fb0 --- /dev/null +++ b/tests/cpp/t23657.nim @@ -0,0 +1,54 @@ +discard """ + targets: "cpp" + cmd: "nim cpp -r $file" + output: ''' +1.0 +1.0 +''' + +""" +{.emit:"""/*TYPESECTION*/ +struct Point { + float x, y, z; + Point(float x, float y, float z): x(x), y(y), z(z) {} + Point() = default; +}; +struct Direction { + float x, y, z; + Direction(float x, float y, float z): x(x), y(y), z(z) {} + Direction() = default; +}; +struct Axis { + Point origin; + Direction direction; + Axis(Point origin, Direction direction): origin(origin), direction(direction) {} + Axis() = default; +}; + +""".} + +type + Point {.importcpp.} = object + x, y, z: float + + Direction {.importcpp.} = object + x, y, z: float + + Axis {.importcpp.} = object + origin: Point + direction: Direction + +proc makeAxis(origin: Point, direction: Direction): Axis {. constructor, importcpp:"Axis(@)".} +proc makePoint(x, y, z: float): Point {. constructor, importcpp:"Point(@)".} +proc makeDirection(x, y, z: float): Direction {. constructor, importcpp:"Direction(@)".} + +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) +var axis2Ctor = makeAxis(makePoint(1.0, 2.0, 3.0), makeDirection(4.0, 5.0, 6.0)) #Do not triggers + +proc main() = #Do not triggers as Tx are inside the body + let test = makeAxis(Point(x: 1.0, y: 2.0, z: 3.0), Direction(x: 4.0, y: 5.0, z: 6.0)) + echo test.origin.x + +main() + +echo $axis1.origin.x #Make sures it's init \ No newline at end of file |