From 7fd8c00ae745111ba2e5adef527332d7162de068 Mon Sep 17 00:00:00 2001 From: Paul Backus Date: Mon, 7 Jun 2021 10:53:42 -0400 Subject: [PATCH] Make matchImpl return auto ref again Fixes #65 on Github, a regression introduced in 88b527bc (Github PR #50) --- src/sumtype.d | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/sumtype.d b/src/sumtype.d index 282f4fe..5579989 100644 --- a/src/sumtype.d +++ b/src/sumtype.d @@ -1679,7 +1679,7 @@ private size_t stride(size_t dim, lengths...)() private template matchImpl(Flag!"exhaustive" exhaustive, handlers...) { - auto matchImpl(SumTypes...)(auto ref SumTypes args) + auto ref matchImpl(SumTypes...)(auto ref SumTypes args) if (allSatisfy!(isSumType, SumTypes) && args.length > 0) { enum typeCount(SumType) = SumType.Types.length; @@ -2111,6 +2111,15 @@ version (D_Exceptions) assert(value.get!double.isClose(6.28)); } +// Handlers that return by ref +@safe unittest { + SumType!int x = 123; + + x.match!(ref (ref int n) => n) = 456; + + assert(x.match!((int n) => n == 456)); +} + // Unreachable handlers @safe unittest { alias MySum = SumType!(int, string);