Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

warning 229 when view "enum struct" as an array #964

Open
Localia-cn opened this issue May 18, 2024 · 2 comments
Open

warning 229 when view "enum struct" as an array #964

Localia-cn opened this issue May 18, 2024 · 2 comments

Comments

@Localia-cn
Copy link

Localia-cn commented May 18, 2024

Compiler version: 1.12.0.7134

A warning will be prompted when using view_as to convert an enum struct to an array type other than any[].

enum struct TestStruct
{
	float x;
	float y;
	float z;
}

void FuncFloat(const float input[3], float output[3])
{
	output = input;
}

void FuncAny(const any input[3], any output[3])
{
	output = input;
}

public void OnPluginStart()
{
	TestStruct v1;

	float vec[3];
	vec = view_as<float>(v1); // warning 229: index tag mismatch (symbol "v1")

	FuncFloat(view_as<float>(v1), view_as<float>(v1));	  // warning 229: index tag mismatch (symbol "v1")
	FuncAny(view_as<float>(v1), view_as<float>(v1));	  // this is no problem
}


@Localia-cn Localia-cn changed the title trigger warning when using "enum struct" with "view_as" trigger warning when using "enum struct" with "view_as" {compiler} May 18, 2024
@Localia-cn Localia-cn changed the title trigger warning when using "enum struct" with "view_as" {compiler} trigger warning when using "enum struct" with "view_as" May 18, 2024
@Localia-cn Localia-cn changed the title trigger warning when using "enum struct" with "view_as" warning 229 when view "enum struct" as an array Nov 29, 2024
@dvander
Copy link
Member

dvander commented Nov 29, 2024

Enum structs can only be converted to "any[]". We could consider a rule where if the inner types are all the same, this kind of conversion would work. But it's a bit esoteric so I'd rather gauge interest/usefulness.

@Localia-cn
Copy link
Author

Enum structs can only be converted to "any[]". We could consider a rule where if the inner types are all the same, this kind of conversion would work. But it's a bit esoteric so I'd rather gauge interest/usefulness.

How about only checking if the sizes of enum struct and array are equal? Similar to allowing the conversion between int[4] and float[4]. The purpose of using view_as is inherently to convert one type to another, as seen in the common conversion between int and Handle types in Sourcemod plugins. Those who use view_as should be aware of what they are doing, and converting to seemingly mismatched variable types should not be a concern.

If such conversions are allowed, people can define their own Vector3 type and directly intermix it with functions in Sourcemod that use float[3] as parameters. Angle, Vector, and Point will have clearer distinctions, and their methods can be isolated through enum structs, which is very helpful for improving the readability of some complex mathematical computation code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants