From 4f0510d2c9eb796d6ead2419f9fd344f3861abce Mon Sep 17 00:00:00 2001 From: Vijay Nayar Date: Tue, 11 Jun 2024 14:01:33 +0200 Subject: [PATCH] Add conditional __compiles check before calling __traits(getOverloads, ...) in AutowiredRegistration.getPreDestructor. --- source/poodinis/autowire.d | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/source/poodinis/autowire.d b/source/poodinis/autowire.d index 6002f00..8afd91c 100644 --- a/source/poodinis/autowire.d +++ b/source/poodinis/autowire.d @@ -309,12 +309,14 @@ class AutowiredRegistration(RegistrationType : Object) : Registration { private void delegate() getPreDestructor(RegistrationType instance) { void delegate() preDestructor = null; static foreach (memberName; __traits(allMembers, RegistrationType)) { - static foreach (overload; __traits(getOverloads, RegistrationType, memberName)) { - static if (__traits(compiles, __traits(getProtection, overload)) - && __traits(getProtection, overload) == "public" - && isFunction!overload - && hasUDA!(overload, PreDestroy)) { - preDestructor = &__traits(getMember, instance, memberName); + static if (__traits(compiles, __traits(getOverloads, RegistrationType, memberName))) { + static foreach (overload; __traits(getOverloads, RegistrationType, memberName)) { + static if (__traits(compiles, __traits(getProtection, overload)) + && __traits(getProtection, overload) == "public" + && isFunction!overload + && hasUDA!(overload, PreDestroy)) { + preDestructor = &__traits(getMember, instance, memberName); + } } } }