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
tagof(<tag name>:) in a switch statement bug #20
Comments
Another bug related to the tagof operator: #include <console>
#include <float>
stock PrintInt(i)
printf("int: %d\n", i);
stock PrintFloat(Float:f)
printf("float: %f\n", f);
stock PrintBool(bool:b)
printf("bool: %s\n", (b)?("true"):("false"));
stock Print({_, Float, bool}:arg, arg_tag=tagof(arg))
{
switch(arg_tag)
{
case (tagof(_:)):
PrintInt(_:arg);
case (tagof(Float:)):
PrintFloat(Float:arg);
case (tagof(bool:)):
PrintBool(bool:arg);
}
}
main()
{
print("--Function overloading emulation test--\n");
Print(1);
Print(1.0);
Print(true);
} Output:
Note the lack of the "int: 1" line. stock Print({_, Float, bool}:arg, arg_tag=tagof(arg))
{
printf("arg_tag = %d\n", arg_tag);
/*
switch(arg_tag)
{
case (tagof(_:)):
PrintInt(_:arg);
case (tagof(Float:)):
PrintFloat(Float:arg);
case (tagof(bool:)):
PrintBool(bool:arg);
}
*/
}
main()
{
print("--Function overloading emulation test--\n");
printf("tagof(_:) = %d\n", tagof(_:));
printf("tagof(Float:) = %d\n", tagof(Float:));
printf("tagof(bool:) = %d\n", tagof(bool:));
Print(1);
Print(1.0);
Print(true);
} And here's what I got:
|
The bug is that tagof(_:) should be 0, not -2147483648. |
Fixed in commit a25041a |
This bug was originally discovered by @ziggi.
When I try to compile this the compiler shows a bunch of error messages:
But if I put the tagof expressions into parentheses...
... the code compiles and works normally.
The text was updated successfully, but these errors were encountered: