www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Error: TypeInfo.equals is not implemented

reply Andre <andre s-e-a-p.de> writes:
Hi,

I do not understand the following error message. I have template 
structure Decimal, which is used in a OrderDb structure.

Comparing two OrderDb structures is working, but trying to compare
two OrderDb array structures ends with an error message:
object.Error: TypeInfo.equals is not implemented.

Kind regards
André

--- Code ---

import std.traits: isInstanceOf;

struct Decimal(int precision, int scale){
	bool opEquals(T)(T d)
		if (isInstanceOf!(Decimal, T))
	{
		return false;
	}
}

struct OrderDb{
	string orderId;
	Decimal!(10,2) amount;
}

void main(){
	auto o1 = OrderDb();
	auto o2 = OrderDb();
	if (o1 == o2) {}; // Works
	if ([o1] == [o2]) {}; // object.Error: TypeInfo.equals is not implemented
}
Feb 08 2014
parent reply "Stanislav Blinov" <stanislav.blinov gmail.com> writes:
opEquals should be const:

struct Decimal(int precision, int scale){
	bool opEquals(T)(T d) const
		if (isInstanceOf!(Decimal, T))
	{
		return false;
	}
}
Feb 08 2014
parent reply "bearophile" <bearophileHUGS lycos.com> writes:
Stanislav Blinov:

 opEquals should be const:

 struct Decimal(int precision, int scale){
 	bool opEquals(T)(T d) const
 		if (isInstanceOf!(Decimal, T))
 	{
 		return false;
 	}
 }
DMD needs to give better error messages in such cases. Bye, bearophile
Feb 08 2014
parent reply "Stanislav Blinov" <stanislav.blinov gmail.com> writes:
On Saturday, 8 February 2014 at 14:15:56 UTC, bearophile wrote:

 DMD needs to give better error messages in such cases.
Naturally. Especially since that was a runtime exception %\
Feb 08 2014
parent reply "bearophile" <bearophileHUGS lycos.com> writes:
Stanislav Blinov:

 Naturally. Especially since that was a runtime exception %\
Is this already in a bugzilla entry? Bye, bearophile
Feb 08 2014
parent reply "Stanislav Blinov" <stanislav.blinov gmail.com> writes:
On Saturday, 8 February 2014 at 15:51:11 UTC, bearophile wrote:

 Is this already in a bugzilla entry?
Can't find anything similar. I'll reduce and post it.
Feb 08 2014
parent reply "Stanislav Blinov" <stanislav.blinov gmail.com> writes:
https://d.puremagic.com/issues/show_bug.cgi?id=12108
Feb 08 2014
parent Andre <andre s-e-a-p.de> writes:
Am 08.02.2014 17:14, schrieb Stanislav Blinov:
 https://d.puremagic.com/issues/show_bug.cgi?id=12108
Thanks a lot. Kind regards André
Feb 08 2014