Adding support for UInt-to-char conversion (#6425)

This pull request adds support for integer-to-char conversion, allowing
the compiler to correctly handle character casting, implementing part of
the issue #5922.

```carbon
import Core library "io";

fn Run() -> i32 {
	var i : i32 = 65;
	var ch: char = (i as char); // Support implemented!
	Core.PrintChar(ch); // Print 'A'
	return 0;
}
```

---------

Co-authored-by: Dana Jansens <danakj@orodu.net>
Co-authored-by: Carbon Infra Bot <carbon-external-infra@google.com>
This commit is contained in:
Vinicius Silva
2026-01-21 21:48:49 +00:00
committed by GitHub
co-authored by Dana Jansens Carbon Infra Bot
parent 08669493b5
commit f42352759f
6 changed files with 57 additions and 0 deletions
@@ -446,6 +446,10 @@ constexpr BuiltinInfo CharConvertChecked = {
"char.convert_checked",
ValidateSignature<auto(CharLiteral)->CharCompatible>};
// Converts from an integer type to a char-compatible type (u8/adapted Char).
constexpr BuiltinInfo IntConvertChar = {
"int.convert_char", ValidateSignature<auto(AnyInt)->CharCompatible>};
// Converts between integer types, truncating if necessary.
constexpr BuiltinInfo IntConvert = {"int.convert",
ValidateSignature<auto(AnyInt)->AnyInt>};
@@ -816,6 +820,7 @@ auto BuiltinFunctionKind::IsCompTimeOnly(const File& sem_ir,
return true;
case IntConvert:
case IntConvertChar:
case IntSNegate:
case IntComplement:
case IntSAdd: