diff --git a/include/libcamera/base/signal.h b/include/libcamera/base/signal.h
index 2bac5a9832..71d585712e 100644
--- a/include/libcamera/base/signal.h
+++ b/include/libcamera/base/signal.h
@@ -109,19 +109,12 @@ public:
 	void disconnect(T *obj, R (T::*func)(Args...))
 	{
 		SignalBase::disconnect([obj, func](SlotList::iterator &iter) {
-			BoundMethodArgs<R, Args...> *slot =
-				static_cast<BoundMethodArgs<R, Args...> *>(*iter);
-
-			if (!slot->match(obj))
+			if (!(*iter)->match(obj))
 				return false;
 
-			/*
-			 * If the object matches the slot, the slot is
-			 * guaranteed to be a member slot, so we can safely
-			 * cast it to BoundMethodMember<T, Args...> to match
-			 * func.
-			 */
-			return static_cast<BoundMethodMember<T, R, Args...> *>(slot)->match(func);
+			auto *slot = dynamic_cast<BoundMethodMember<T, R, Args...> *>(*iter);
+
+			return slot && slot->match(func);
 		});
 	}
 
@@ -129,13 +122,12 @@ public:
 	void disconnect(R (*func)(Args...))
 	{
 		SignalBase::disconnect([func](SlotList::iterator &iter) {
-			BoundMethodArgs<R, Args...> *slot =
-				static_cast<BoundMethodArgs<R, Args...> *>(*iter);
-
-			if (!slot->match(nullptr))
+			if (!(*iter)->match(nullptr))
 				return false;
 
-			return static_cast<BoundMethodStatic<R, Args...> *>(slot)->match(func);
+			auto *slot = dynamic_cast<BoundMethodStatic<R, Args...> *>(*iter);
+
+			return slot && slot->match(func);
 		});
 	}
 
diff --git a/test/signal.cpp b/test/signal.cpp
index 3f596b22db..f3d8d0cdb5 100644
--- a/test/signal.cpp
+++ b/test/signal.cpp
@@ -209,6 +209,39 @@ protected:
 			return TestFail;
 		}
 
+		/* Test disconnection of various types at once. */
+		{
+			static unsigned int staticCount = 0;
+
+			struct Receiver {
+				static void staticSlot() { staticCount += 1; }
+				void slot() { count += 1; }
+
+				unsigned int count = 0;
+			} o1, o2;
+
+			signalVoid_.disconnect();
+
+			signalVoid_.connect(&o1, [&] { o1.count += 1; });
+			signalVoid_.connect(&o1, &Receiver::slot);
+			signalVoid_.connect(&Receiver::staticSlot);
+
+			signalVoid_.connect(&o2, [&] { o2.count += 1; });
+			signalVoid_.connect(&o2, &Receiver::slot);
+			signalVoid_.connect(&Receiver::staticSlot);
+
+			signalVoid_.disconnect(&o1, &Receiver::slot);
+			signalVoid_.disconnect(&Receiver::staticSlot);
+			signalVoid_.disconnect(&o1);
+
+			signalVoid_.emit();
+
+			if (o1.count != 0 || o2.count != 2 || staticCount != 0) {
+				cout << "Signal disconnection failed" << endl;
+				return TestFail;
+			}
+		}
+
 		/* ----------------- Signal -> Object tests ----------------- */
 
 		/*
