www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - lovely compiler error message - incompatible types

reply "Laeeth Isharc" <laeethnospam nospamlaeeth.com> writes:
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
next sibling parent Justin Whear <justin economicmodeling.com> writes:
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
prev sibling next sibling parent "anonymous" <anonymous example.com> writes:
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
prev sibling parent reply Steven Schveighoffer <schveiguy yahoo.com> writes:
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
next sibling parent "Laeeth Isharc" <Laeeth.nospam nospam-laeeth.com> writes:
On Thursday, 2 July 2015 at 18:01:39 UTC, Steven Schveighoffer 
wrote:
 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
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.
Jul 02 2015
prev sibling parent reply "Laeeth Isharc" <laeethnospam nospamlaeeth.com> writes:
 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
https://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
parent reply Justin Whear <justin economicmodeling.com> writes:
On Thu, 02 Jul 2015 21:03:37 +0000, Laeeth Isharc wrote:

 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
https://gist.github.com/Laeeth/6251fa731e4cee84bcdc not really a proper implementation. I wanted something as a placeholder today that I could implement properly later...
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)
Jul 02 2015
parent "Laeeth Isharc" <Laeeth.nospam nospam-laeeth.com> writes:
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:

 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
https://gist.github.com/Laeeth/6251fa731e4cee84bcdc not really a proper implementation. I wanted something as a placeholder today that I could implement properly later...
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)
Thanks v much ! Of course I guess it isn't numeric to the compiler...
Jul 02 2015