www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - What am I doing wrong here?

reply "Martin" <martinbbjerregaard gmail.com> writes:
Hey everyone, I'm new to D so bare with me please. I've been 
trying to figure out what's up with the strange forward refernce 
errors the compiler (DMD 2.060) is giving me. Here's a code 
snippet that's generating a forward reference error:

public class AliasTestClass(alias func)
{
	
	static assert(__traits(isStaticFunction, func));
		
}

public class TestClass
{
	
	private AliasTestClass!(randomFunction) test; // <-----
		
	public static void randomFunction()
	{
	}
	
}

The strange part about it is that if I surround the 
randomFunction parameter with another pair of paranthesis like so

private AliasTestClass!((randomFunction)) test;

It works just fine. If I don't, however, I get a forward 
reference error:
"Error: template instance main.AliasTestClass!(randomFunction) 
forward reference of randomFunction"

Am I doing anything wrong or is this some kind of bug?
Oct 14 2012
parent reply "Simen Kjaeraas" <simen.kjaras gmail.com> writes:
On 2012-10-14, 14:28, Martin wrote:

 Hey everyone, I'm new to D so bare with me please. I've been trying to  
 figure out what's up with the strange forward refernce errors the  
 compiler (DMD 2.060) is giving me. Here's a code snippet that's  
 generating a forward reference error:

 public class AliasTestClass(alias func)
 {
 	
 	static assert(__traits(isStaticFunction, func));
 		
 }

 public class TestClass
 {
 	
 	private AliasTestClass!(randomFunction) test; // <-----
 		
 	public static void randomFunction()
 	{
 	}
 	
 }

 The strange part about it is that if I surround the randomFunction  
 parameter with another pair of paranthesis like so

 private AliasTestClass!((randomFunction)) test;

 It works just fine. If I don't, however, I get a forward reference error:
 "Error: template instance main.AliasTestClass!(randomFunction) forward  
 reference of randomFunction"

 Am I doing anything wrong or is this some kind of bug?
It's a bug. Maybe it's already in Bugzilla (there are some forward-ref bugs there already). Please file: http://d.puremagic.com/issues/enter_bug.cgi -- Simen
Oct 14 2012
parent "Martin" <martinbbjerregaard gmail.com> writes:
On Sunday, 14 October 2012 at 12:58:24 UTC, Simen Kjaeraas wrote:
 On 2012-10-14, 14:28, Martin wrote:

 Hey everyone, I'm new to D so bare with me please. I've been 
 trying to figure out what's up with the strange forward 
 refernce errors the compiler (DMD 2.060) is giving me. Here's 
 a code snippet that's generating a forward reference error:

 public class AliasTestClass(alias func)
 {
 	
 	static assert(__traits(isStaticFunction, func));
 		
 }

 public class TestClass
 {
 	
 	private AliasTestClass!(randomFunction) test; // <-----
 		
 	public static void randomFunction()
 	{
 	}
 	
 }

 The strange part about it is that if I surround the 
 randomFunction parameter with another pair of paranthesis like 
 so

 private AliasTestClass!((randomFunction)) test;

 It works just fine. If I don't, however, I get a forward 
 reference error:
 "Error: template instance main.AliasTestClass!(randomFunction) 
 forward reference of randomFunction"

 Am I doing anything wrong or is this some kind of bug?
It's a bug. Maybe it's already in Bugzilla (there are some forward-ref bugs there already). Please file: http://d.puremagic.com/issues/enter_bug.cgi
Oh, thank you for clarifying, I thought I was doing something wrong :)
Oct 14 2012