Open zah opened 4 years ago
but expression 'GreenBytesint' is immutable, not 'var'
This was fixed in #18837, the remaining problem is converting to a var
type which is lower priority, a more simple case is:
type Foo = distinct int
var x = Foo(1)
type IntVar = var int
IntVar(x) += 1
/usercode/nimcache/@min.nim.c: In function 'NimMainModule':
/usercode/nimcache/@min.nim.c:136:48: error: invalid type argument of unary '*' (have 'NI' {aka 'long long int'})
136 | TM__JXJjWlLylejo6nWONmO6cA_2 = addInt((*x__EGWKGClUlppqAonIP2rgfg), ((NI) 1));
| ^~~~~~~~~~~~~~~~~~~~~~~~~~
/usercode/nimcache/@min.nim.c:137:10: error: invalid type argument of unary '*' (have 'NI' {aka 'long long int'})
137 | (*x__EGWKGClUlppqAonIP2rgfg) = (NI)(TM__JXJjWlLylejo6nWONmO6cA_2);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~
Consider the following program:
The
when false
statement demonstrates a coercion error that happens only when theGreenBytes
distinct type is also a generic type.The alternative way to force the coercion tricks the compiler into generating the following invalid code:
Notice how
data
is dereferenced unnecessarily which leads to a segfault. It should be noted that the code works correctly in C++ mode, where the compiler uses reference types.