Formatter did not properly handle "null" for any, and null for empty faults. #2375

This commit is contained in:
Christoffer Lerno
2025-08-06 11:23:56 +02:00
parent 3b6d68ef21
commit 9c770f360e
3 changed files with 35 additions and 2 deletions

View File

@@ -146,10 +146,12 @@ fn usz? Formatter.out_str(&self, any arg) @private
case VOID:
return self.out_substr("void");
case FAULT:
return self.out_substr((*(fault*)arg.ptr).nameof);
fault f = *(fault*)arg.ptr;
return self.out_substr(f ? f.nameof : "(nofault)");
case INTERFACE:
case ANY:
return self.out_str(*(any*)arg);
any a = *(any*)arg;
return a ? self.out_str(a) : self.out_substr("(null)");
case OPTIONAL:
unreachable();
case SIGNED_INT:

View File

@@ -20,6 +20,7 @@
- Parsing difference between "0x00." and "0X00." literals #2371
- Fixed bug generating `$c += 1` when `$c` was derived from a pointer but behind a cast.
- Compiler segfault when using bitwise not on number literal cast to bitstruct #2373.
- Formatter did not properly handle "null" for any, and null for empty faults. #2375
### Stdlib changes
- Add `==` to `Pair`, `Triple` and TzDateTime. Add print to `Pair` and `Triple`.

View File

@@ -0,0 +1,30 @@
module format_test;
import std::io;
interface Decl
{
}
struct TestS (Decl, Printable)
{
int a;
}
fn usz? TestS.to_format(&self, Formatter* formatter) @dynamic => formatter.printf("[%d]", self.a);
faultdef DERP;
fn void various_cornercases() @test
{
TestS a = {100};
Decl z = &a;
test::eq(string::tformat("%s", z), "[100]");
fault p; fault o = DERP;
test::eq(string::tformat("%s|%s", p, o), "(nofault)|format_test::DERP");
Decl y;
test::eq(string::tformat("%s", y), "(null)");
int* x;
test::eq(string::tformat("%s", x), "0x0");
}