From 52de4258e9e973f453909176b20bebead2f86dd6 Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Sun, 24 Nov 2024 16:41:27 -0500 Subject: [PATCH] Better handling for NULL optional types --- types.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/types.c b/types.c index b57ff7b..75a3797 100644 --- a/types.c +++ b/types.c @@ -13,6 +13,9 @@ #include "types.h" CORD type_to_cord(type_t *t) { + if (!t) + return "(Unknown type)"; + switch (t->tag) { case UnknownType: return "???"; case AbortType: return "Abort"; @@ -75,7 +78,11 @@ CORD type_to_cord(type_t *t) { return tagged->name; } case OptionalType: { - return CORD_all(type_to_cord(Match(t, OptionalType)->type), "?"); + type_t *opt = Match(t, OptionalType)->type; + if (opt) + return CORD_all(type_to_cord(opt), "?"); + else + return "(Unknown optional type)"; } case TypeInfoType: { return CORD_all("Type$info(", Match(t, TypeInfoType)->name, ")");