Anonymous types make some errors misleading
When a type needs to be named in an error, anonymous types are just represented by the field's name. This has some overlooked consequences. For example the following code:
struct Foo
{
bitstruct anon : char
{
bool a : 0;
char b : 1..7;
}
}
fn void test()
{
Foo foo;
char x = 32;
foo.anon = x; // Implicit cast not allowed
}
produces an error suggesting a syntactically incorrect fix
Error: Implicitly casting 'char' to 'anon' is not permitted,
but you may do an explicit cast by placing '(anon)' before the expression
Where it should just say that casts to anonymous types are forbidden.
Other error messages might also be affected, although i have not found any.
Could you have a look if it's better now?
@lerno Using the example code:
struct Foo
{
bitstruct anon : char
{
bool a : 0;
char b : 1..7;
}
}
fn void test()
{
Foo foo;
char x = 32;
foo.anon = x; // Implicit cast not allowed
}
Now results in a nicer error message:
Error: Implicitly casting 'char' to the inner type 'Foo.anon' is not permitted, but you may do an explicit cast by placing '($typefrom(Foo.anon.typeid))' before the expression.
When using the suggestion, it will then proceed to compile as expected.
Thank you for checking!