From 8ee1afd7f2c8434902627077bb2ad95284f70786 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6nke=20Ludwig?= Date: Fri, 22 Feb 2019 03:02:50 +0100 Subject: [PATCH] Don't define ambiguous opBinary/opBinaryRight overloads. Fixes #18. --- source/taggedalgebraic.d | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/source/taggedalgebraic.d b/source/taggedalgebraic.d index 0c1b18f..82447ad 100644 --- a/source/taggedalgebraic.d +++ b/source/taggedalgebraic.d @@ -208,7 +208,9 @@ struct TaggedAlgebraic(U) if (is(U == union) || is(U == struct)) /// Enables the use of binary operators with the stored value. auto opBinary(string op, T, this TA)(auto ref T other) if (hasOp!(TA, OpKind.binary, op, T)) { return implementOp!(OpKind.binary, op)(this, other); } /// Enables the use of binary operators with the stored value. - auto opBinaryRight(string op, T, this TA)(auto ref T other) if (hasOp!(TA, OpKind.binaryRight, op, T)) { return implementOp!(OpKind.binaryRight, op)(this, other); } + auto opBinaryRight(string op, T, this TA)(auto ref T other) if (hasOp!(TA, OpKind.binaryRight, op, T) && !isInstanceOf!(TaggedAlgebraic, T)) { return implementOp!(OpKind.binaryRight, op)(this, other); } + /// ditto + auto opBinaryRight(string op, T, this TA)(auto ref T other) if (hasOp!(TA, OpKind.binaryRight, op, T) && isInstanceOf!(TaggedAlgebraic, T) && !hasOp!(T, OpKind.opBinary, op, TA)) { return implementOp!(OpKind.binaryRight, op)(this, other); } /// Enables operator assignments on the stored value. auto opOpAssign(string op, T, this TA)(auto ref T other) if (hasOp!(TA, OpKind.binary, op~"=", T)) { return implementOp!(OpKind.binary, op~"=")(this, other); } /// Enables indexing operations on the stored value.