jckarter / clay

The Clay programming language
http://claylabs.com/clay
Other
404 stars 34 forks source link

use checked cast when converting to Char and to UniChar #309

Closed stepancheg closed 12 years ago

stepancheg commented 12 years ago

Before this commit

UniChar(Char(-1))

resulted in UniChar(4294967295). This is definitely not what developer wants. After this commit UniChar(Char(-1)) is integer overflow error, and that's correct, because there is no single way to represent non-ASCII Char values as Unicode characters.

And vice versa, before this commit

Char(UniChar(10000))

resulted in Char that does not represent original UniChar, so this operation should also be integer overflow.

However, 8bit characters are often represented as UInt32 values in range 0..256. For that case, Char(I) now has two overloads: for signed integer and for unsigned integer parameter.