c3lang / c3c

Compiler for the C3 language
https://c3-lang.org
GNU Lesser General Public License v3.0
2.66k stars 157 forks source link

Anonymous types make some errors misleading #1471

Open chri-k opened 3 days ago

chri-k commented 3 days ago

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.

lerno commented 13 hours ago

Could you have a look if it's better now?