diff --git a/src/Hedgehog.Xunit/InternalLogic.fs b/src/Hedgehog.Xunit/InternalLogic.fs index 7e2d4df..ddb20a2 100644 --- a/src/Hedgehog.Xunit/InternalLogic.fs +++ b/src/Hedgehog.Xunit/InternalLogic.fs @@ -116,13 +116,19 @@ let rec yieldAndCheckReturnValue (x: obj) = match x with | :? bool as b -> if not b then TestReturnedFalseException() |> raise | :? Task as t -> Async.AwaitTask t |> yieldAndCheckReturnValue + | :? Task as t -> Async.AwaitTask t |> yieldAndCheckReturnValue | _ when x <> null && x.GetType().IsGenericType && x.GetType().GetGenericTypeDefinition().IsSubclassOf typeof -> - typeof - .GetMethods() - .First(fun x -> x.Name = "AwaitTask" && x.IsGenericMethod) - .MakeGenericMethod(x.GetType().GetGenericArguments()) - .Invoke(null, [|x|]) - |> yieldAndCheckReturnValue + let genType = x.GetType().GetGenericTypeDefinition() + if not genType.ContainsGenericParameters then + let t = x :?> Task + Async.AwaitTask t |> yieldAndCheckReturnValue + else + typeof + .GetMethods() + .First(fun x -> x.Name = "AwaitTask" && x.IsGenericMethod) + .MakeGenericMethod(x.GetType().GetGenericArguments()) + .Invoke(null, [|x|]) + |> yieldAndCheckReturnValue | :? Task as t -> Async.AwaitTask t |> yieldAndCheckReturnValue | :? Async as a -> Async.RunSynchronously(a, cancellationToken = CancellationToken.None) |> yieldAndCheckReturnValue | _ when x <> null && x.GetType().IsGenericType && x.GetType().GetGenericTypeDefinition() = typedefof> ->