digitalmars.D.learn - lovely compiler error message - incompatible types
- Laeeth Isharc (21/21) Jul 02 2015 Hi.
- Justin Whear (2/9) Jul 02 2015 Can you show the signature for FixedDecimal's opBinary?
- anonymous (42/58) Jul 02 2015 From the error messages it looks you didn't implement the
- Steven Schveighoffer (4/22) Jul 02 2015 Can you post the signature to the operator overload? I have an idea of
- Laeeth Isharc (6/42) Jul 02 2015 Thank you for this. Will do when back at my pc. It went away
- Laeeth Isharc (3/7) Jul 02 2015 https://gist.github.com/Laeeth/6251fa731e4cee84bcdc
- Justin Whear (6/15) Jul 02 2015 I think the issue is that your opBinary requires that isNumeric!T be
- Laeeth Isharc (3/20) Jul 02 2015 Thanks v much ! Of course I guess it isn't numeric to the
Hi. It's not easy to reduce, but I will have a go if other options fail. Any thoughts on what could be leading to the following: ./../../marketdata/source/pricebar.d(397): Error: incompatible types for ((bar.high) + (bar.low)): 'FixedDecimal!(int, 8)' and 'FixedDecimal!(int, 8)' ../../../marketdata/source/pricebar.d(399): Error: incompatible types for ((bar.high) + (bar.low)): 'FixedDecimal!(int, 8)' and 'FixedDecimal!(int, 8)' ../../../marketdata/source/pricebar.d(547): Error: incompatible types for ((trueHigh(bars)) - (trueLow(bars))): 'FixedDecimal!(int, 8)' and 'FixedDecimal!(int, 8)' FixedDecimal is a fixed decimal point struct that stores values as an int or long and takes number of decimal places as the second compile term argument. It's possible, if not likely I have made a mistake in implementing operator overloads. Any thoughts on whether this is the likely cause, and if so which ones are likely to be the problem? Thanks. Laeeth.
Jul 02 2015
On Thu, 02 Jul 2015 17:33:28 +0000, Laeeth Isharc wrote:FixedDecimal is a fixed decimal point struct that stores values as an int or long and takes number of decimal places as the second compile term argument. It's possible, if not likely I have made a mistake in implementing operator overloads. Any thoughts on whether this is the likely cause, and if so which ones are likely to be the problem?Can you show the signature for FixedDecimal's opBinary?
Jul 02 2015
On Thursday, 2 July 2015 at 17:33:29 UTC, Laeeth Isharc wrote:Any thoughts on what could be leading to the following: ./../../marketdata/source/pricebar.d(397): Error: incompatible types for ((bar.high) + (bar.low)): 'FixedDecimal!(int, 8)' and 'FixedDecimal!(int, 8)' ../../../marketdata/source/pricebar.d(399): Error: incompatible types for ((bar.high) + (bar.low)): 'FixedDecimal!(int, 8)' and 'FixedDecimal!(int, 8)' ../../../marketdata/source/pricebar.d(547): Error: incompatible types for ((trueHigh(bars)) - (trueLow(bars))): 'FixedDecimal!(int, 8)' and 'FixedDecimal!(int, 8)' FixedDecimal is a fixed decimal point struct that stores values as an int or long and takes number of decimal places as the second compile term argument. It's possible, if not likely I have made a mistake in implementing operator overloads. Any thoughts on whether this is the likely cause, and if so which ones are likely to be the problem?From the error messages it looks you didn't implement the operator overloads properly. You get the same message when FixedDecimal doesn't overload anything at all: ---- struct FixedDecimal(T, uint n) {} void main() { FixedDecimal!(int, 8) a, b; auto c = a + b; /* line 5 */ } ---- test.d(5): Error: incompatible types for ((a) + (b)): 'FixedDecimal!(int, 8u)' and 'FixedDecimal!(int, 8u)' ---- You can get a more specific error by instantiating/calling things explicitly. For example, here I messed up the parameter type: ---- struct FixedDecimal(T, uint n) { FixedDecimal opBinary(string op)(FixedDecimal!(T, 0)) { return FixedDecimal.init; } } void main() { FixedDecimal!(int, 8) a, b; auto c = a + b; /* line 11 */ auto d = a.opBinary!"+"(b); /* line 12 */ } ---- test.d(11): Error: incompatible types for ((a) + (b)): 'FixedDecimal!(int, 8u)' and 'FixedDecimal!(int, 8u)' test.d(12): Error: function test.FixedDecimal!(int, 8u).FixedDecimal.opBinary!"+".opBinary (FixedDecimal!(int, 0u) _param_0) is not callable using argument types (FixedDecimal!(int, 8u)) ---- The error for line 11 just says that something went wrong. The one for line 12 is a little more helpful.
Jul 02 2015
On 7/2/15 1:33 PM, Laeeth Isharc wrote:Hi. It's not easy to reduce, but I will have a go if other options fail. Any thoughts on what could be leading to the following: ../../../marketdata/source/pricebar.d(397): Error: incompatible types for ((bar.high) + (bar.low)): 'FixedDecimal!(int, 8)' and 'FixedDecimal!(int, 8)' .../../../marketdata/source/pricebar.d(399): Error: incompatible types for ((bar.high) + (bar.low)): 'FixedDecimal!(int, 8)' and 'FixedDecimal!(int, 8)' .../../../marketdata/source/pricebar.d(547): Error: incompatible types for ((trueHigh(bars)) - (trueLow(bars))): 'FixedDecimal!(int, 8)' and 'FixedDecimal!(int, 8)' FixedDecimal is a fixed decimal point struct that stores values as an int or long and takes number of decimal places as the second compile term argument. It's possible, if not likely I have made a mistake in implementing operator overloads. Any thoughts on whether this is the likely cause, and if so which ones are likely to be the problem?Can you post the signature to the operator overload? I have an idea of what it might be, but it's difficult to explain without context. -Steve
Jul 02 2015
On Thursday, 2 July 2015 at 18:01:39 UTC, Steven Schveighoffer wrote:On 7/2/15 1:33 PM, Laeeth Isharc wrote:Thank you for this. Will do when back at my pc. It went away when I did alias this to the underlying integer, so I guess that probably confirms what you suggested. But I shouldn't leave it that way.Hi. It's not easy to reduce, but I will have a go if other options fail. Any thoughts on what could be leading to the following: ../../../marketdata/source/pricebar.d(397): Error: incompatible types for ((bar.high) + (bar.low)): 'FixedDecimal!(int, 8)' and 'FixedDecimal!(int, 8)' .../../../marketdata/source/pricebar.d(399): Error: incompatible types for ((bar.high) + (bar.low)): 'FixedDecimal!(int, 8)' and 'FixedDecimal!(int, 8)' .../../../marketdata/source/pricebar.d(547): Error: incompatible types for ((trueHigh(bars)) - (trueLow(bars))): 'FixedDecimal!(int, 8)' and 'FixedDecimal!(int, 8)' FixedDecimal is a fixed decimal point struct that stores values as an int or long and takes number of decimal places as the second compile term argument. It's possible, if not likely I have made a mistake in implementing operator overloads. Any thoughts on whether this is the likely cause, and if so which ones are likely to be the problem?Can you post the signature to the operator overload? I have an idea of what it might be, but it's difficult to explain without context. -Steve
Jul 02 2015
Can you post the signature to the operator overload? I have an idea of what it might be, but it's difficult to explain without context. -Stevehttps://gist.github.com/Laeeth/6251fa731e4cee84bcdc not really a proper implementation. I wanted something as a placeholder today that I could implement properly later...
Jul 02 2015
On Thu, 02 Jul 2015 21:03:37 +0000, Laeeth Isharc wrote:I think the issue is that your opBinary requires that isNumeric!T be true. This is the case if FixedDecimal is allowed to decay to the underlying int which is why it works when you use the alias this. I recommend removing the alias this and adding another overload like this: FixedDecimal opBinary(string s, T : FixedDecimal)(const T rhs)Can you post the signature to the operator overload? I have an idea of what it might be, but it's difficult to explain without context. -Stevehttps://gist.github.com/Laeeth/6251fa731e4cee84bcdc not really a proper implementation. I wanted something as a placeholder today that I could implement properly later...
Jul 02 2015
On Thursday, 2 July 2015 at 21:19:19 UTC, Justin Whear wrote:On Thu, 02 Jul 2015 21:03:37 +0000, Laeeth Isharc wrote:Thanks v much ! Of course I guess it isn't numeric to the compiler...I think the issue is that your opBinary requires that isNumeric!T be true. This is the case if FixedDecimal is allowed to decay to the underlying int which is why it works when you use the alias this. I recommend removing the alias this and adding another overload like this: FixedDecimal opBinary(string s, T : FixedDecimal)(const T rhs)Can you post the signature to the operator overload? I have an idea of what it might be, but it's difficult to explain without context. -Stevehttps://gist.github.com/Laeeth/6251fa731e4cee84bcdc not really a proper implementation. I wanted something as a placeholder today that I could implement properly later...
Jul 02 2015