From 81ce86ef67ba041e3cd8b8d16457ab5b498a33f9 Mon Sep 17 00:00:00 2001 From: Nicholas Wilson Date: Sun, 27 Oct 2024 17:27:20 +0800 Subject: [PATCH] remove uses of `classinfo`, rebases part of #7445 (#9063) --- std/conv.d | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/std/conv.d b/std/conv.d index 2e2c7342abd..6df3bd0b24d 100644 --- a/std/conv.d +++ b/std/conv.d @@ -917,9 +917,22 @@ if (!is(S : T) && auto result = ()@trusted{ return cast(T) value; }(); if (!result && value) { - throw new ConvException("Cannot convert object of static type " - ~S.classinfo.name~" and dynamic type "~value.classinfo.name - ~" to type "~T.classinfo.name); + string name(TypeInfo ti) @trusted + { + while (auto tc = (cast(TypeInfo_Const) ti)) + { + ti = tc.base; + } + if (auto tinf = (cast(TypeInfo_Interface) ti)) + { + ti = tinf.info; + } + TypeInfo_Class tc = cast(TypeInfo_Class) ti; + assert(tc); + return tc.name; + } + throw new ConvException("Cannot convert object of static type " ~ + name(typeid(S)) ~ " and dynamic type " ~ name(typeid(value)) ~ " to type " ~ name(typeid(T))); } return result; }