www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Strange Compile Error when concatenating arrays

reply "Jeroen Bollen" <jbinero gmail.com> writes:
When I concatenate arrays like this, I get a strange compile 
error:

Error: incompatible types for ((cast(int)a) ~ (cast(int)b)): 
'int' and 'int'

Code:

public ubyte[] toArray(ubyte a, ubyte b, ubyte c) {
	return a ~ b ~ c;
}
Apr 09 2014
parent reply "Jeroen Bollen" <jbinero gmail.com> writes:
On Wednesday, 9 April 2014 at 19:35:49 UTC, Jeroen Bollen wrote:
 When I concatenate arrays like this, I get a strange compile 
 error:

 Error: incompatible types for ((cast(int)a) ~ (cast(int)b)): 
 'int' and 'int'

 Code:

 public ubyte[] toArray(ubyte a, ubyte b, ubyte c) {
 	return a ~ b ~ c;
 }
Oh derp I already figured it out. It still is a strange error message though.
Apr 09 2014
parent "John Colvin" <john.loughran.colvin gmail.com> writes:
On Wednesday, 9 April 2014 at 19:39:13 UTC, Jeroen Bollen wrote:
 On Wednesday, 9 April 2014 at 19:35:49 UTC, Jeroen Bollen wrote:
 When I concatenate arrays like this, I get a strange compile 
 error:

 Error: incompatible types for ((cast(int)a) ~ (cast(int)b)): 
 'int' and 'int'

 Code:

 public ubyte[] toArray(ubyte a, ubyte b, ubyte c) {
 	return a ~ b ~ c;
 }
Oh derp I already figured it out. It still is a strange error message though.
Not really. It gives you the expression, tells you the types are incompatible and tells you what those types were. The reason why you get int is because operations on integral types are promoted to int. public ubyte[] toArray(ubyte a, ubyte b, ubyte c) { return [a, b, c]; }
Apr 09 2014