HaxeFoundation / HaxeFoundation/haxe

HXCPP: incorrect use of ->

Open
#12,704 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
Haxe
Stars
6.9k
Forks
715
Avg merge
2d 2h
Merged PRs (30d)
11

Description

problem: using array access to get a Vec4 from a Matrix class and calling any of its fields `mat[0].x` replaces it with `mat.columns[0]->x`, expected until the `->` part, my set up is
```
struct Vec4 {
union {
struct { double x, y, z, w;};
double v[4];
};

};

struct Mat4 {
union {
struct { Vec4 col0, col1, col2, col3; };
Vec4 columns[4];
double v[16];
};

};
```
and the natives on the Haxe side already have `@:structAccess`, what's important is the `@:arrayAccess` functions:

Vec4:
```
@:arrayAccess inline private function getAt(index:Int):Ref { return untyped __cpp__("{0}.v[{1}]", this, index); }
@:arrayAccess inline private function setAt(index:Int, v:Float):Ref { return untyped __cpp__("{0}.v[{1}] = {2}", this, index, v); }
```
Mat4:
```
@:arrayAccess inline private function getAt(index:Int):Vec4 { return untyped __cpp__("{0}.columns[{1}]", this, index); }
@:arrayAccess inline private function setAt(index:Int, v:Vec4):Vec4 { return untyped __cpp__("{0}.columns[{1}] = {2}", this, index, v); }
```

it should always use a dot instead of `->` when accessing a Vec4 instance, like in these examples:
`vec.x` in Haxe becomes `vec.x` in C++
`vec[0]` becomes `vec.v[0]`
`var vec = mat[0];` becomes `Vec4 & vec1 = mat.columns[0];`
`mat[0][1]` becomes `Vec4 & this7 = mat.columns[0]; this7.v[1];`
but as soon as i try to access a Vec4 field directly from Mat4 like `mat[0].x` it uses `->` instead `mat.columns[0]->x`

after a bit of testing, i found out that this happens fields/methods that are specifically defined in C++, so extern inlined function or fields on the Haxe side dont get affected as they just get pasted

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.