pawn-lang / compiler

Pawn compiler for SA-MP with bug fixes and new features - runs on Windows, Linux, macOS
Other
301 stars 71 forks source link

native operators overload can return arrays #685

Open YashasSamaga opened 2 years ago

YashasSamaga commented 2 years ago

Issue description:

Native operator overloads can specify an array return type. They should have the same semantics as non-native operator overloads. The compiler fails to diagnose it.

Minimal complete verifiable example (MCVE):

This compiles:

native Float:[10]operator+(Float:a, Float:b) = 0;
main () { }

This doesn't:

Float:[10]operator-(Float:a, Float:b) { }
main () { }

Workspace Information:

Daniel-Cortez commented 2 years ago

This doesn't:

Float:[10]operator-(Float:a, Float:b) { }
main () { }

This is because return array sizes are only valid in new-style function declarations that start either from keyword forward, or native. For example, this code

forward Float:[10]operator-(Float:a, Float:b);
main(){ }

would compile as well.

I think the real problem here is that operators aren't actually supposed to return arrays at all, and the compiler doesn't diagnose this. Fixing this shouldn't be hard.

stale[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had recent activity.