Currently we only support, what is sometimes called guaranteed conversion. Using the 'as' operator.
Guaranteed conversion can be verified by the compiler.
I propose to also introduce forced conversion using the operator 'as!' .
The compiler would reject forced conversion if it is not necessary. For example in 'a as! bits32' or 'a as! nat32'.
In the future we will distinguish debug and and release code
generation. In debug code, forced conversion can trap, if the runtime
value does not "fit" into the converted type. In release code we would
use the semantics of C's downcast.
Maybe we will also have 'as?' as soon as we introduce exceptions - which we already planned. 'as?' will throw an exception instead of trapping - also in the release code. Exceptions have to be caught by an exeception handler, for a programm, that is accepted by the compiler.
In your example you would have to use 'as!' instead of 'as'. For the moment we only generate release code.
I still have to check the consequences, before I start implementing this feature.
All the best,
Franz-Josef