xsharp.eu • static class "Functions" within a namespace
Page 1 of 1

static class "Functions" within a namespace

Posted: Sat Aug 04, 2018 10:18 am
by Karl-Heinz
the code below throws two errors:

error XS0103: The name 'Test1' does not exist in the current context
error XS0103: The name 'Test2' does not exist in the current context

Test1() and Test2() exist, but only when qualified names are used they become visible to the compiler. when you activate the #DEFINE __OK__ the name of the static class changes from "Functions" to "Funcs". Now it compiles. It seems the compiler gets confused when the name "Functions" is used within this context.


Code: Select all

// #DEFINE __OK__

#IFDEF __OK__
 USING STATIC khr.Funcs

#ELSE
 USING STATIC khr.Functions
 
#ENDIF 



FUNCTION Start( ) AS VOID

     #ifndef __OK__ 

     // ok, gives no compiler error
 
	 ? khr.Functions.Test1()
	 ? khr.Functions.Test2() 
	 
     #endif 


	? Test1()
	? Test2() 
	
	
RETURN 



BEGIN NAMESPACE khr

#IFDEF __OK__
	STATIC CLASS Funcs
#ELSE		
    STATIC CLASS Functions
#ENDIF     	
    	
     STATIC METHOD Test1()  AS STRING
     	 	
     RETURN "Test1() called"
	
     	
     STATIC METHOD Test2()  AS STRING
     	 	
     RETURN "Test2() called"	
      	
     	
     END CLASS 	


END NAMESPACE

regards
Karl-Heinz

static class "Functions" within a namespace

Posted: Sat Aug 04, 2018 7:12 pm
by Chris
Hi Karl-Heinz,

Yes, this is because the compiler also creates a class named "Functions" under the hood, as a placeholder for all FUNCTIONs, GLOBALs and DEFINEs declared in the code, so your Functions class conflicts with the compiler generated class. I am afraid it will not be easy to fix that, so I suggest lways doing what you did, name your own class as "Funcs", this is what I always do as well. Having said that, it's probbaly a good idea for the compiler to identify this situation and give a better error message, though, will log this, thanks!

Chris

static class "Functions" within a namespace

Posted: Mon Aug 06, 2018 1:29 pm
by Karl-Heinz
Hi Chris,

ok i see what you mean, and what´s added to such a "Functions" class. Question: When i create a DLL from the code below with undef __INCLUDE__ such a compiler generated "Functions" class would not really be needed, right ?

Code: Select all


// #define __INCLUDE__ 
 
BEGIN NAMESPACE khr2

#IFDEF __INCLUDE__
    // ---------------
	GLOBAL GLOBAL_Khr2 := 0 AS INT          // part of the compiler generated static "Functions" 
	DEFINE DEFINE_Khr2 := "1234" AS STRING  // part of the compiler generated static "Functions"  
   FUNCTION GLOBALFunc_khr2() AS INT        // part of the compiler generated static "Functions"  
   	RETURN 12 
   	// ----------------
#ENDIF
 
		
	STATIC CLASS Funcs
   	
     STATIC METHOD Foo()  AS STRING
     	 	
     RETURN "X# Foo() called"			
   
   END CLASS 
   

END NAMESPACE 


BEGIN NAMESPACE khr

#ifdef __INCLUDE__
    //  -----------------
	GLOBAL GLOBAL_Khr := 0 AS INT          // part of the compiler generated static "Functions" 
	DEFINE DEFINE_Khr  := "1234" AS STRING  // part of the compiler generated static "Functions" 
    //  -----------------	
#endif        
                  

	STATIC CLASS Globals
		
       CONST BUFFER_SIZE := 512 AS INT 
       STATIC FILE_NAME := "Output.txt" AS STRING  
       STATIC INITONLY CODE_PREFIX := "US-" AS STRING   
       
	END CLASS   
	
#IFDEF __INCLUDE__
   // ---------
   FUNCTION GLOBALFunc_khr() AS INT         // part of the compiler generated static "Functions"  
   	RETURN 12	
    GLOBAL GLOBAL2_Khr := "asdasd" AS STRING  // part of the compiler generated static "Functions"  
    // -------------
#ENDIF     
    


	STATIC CLASS Funcs
   	
     STATIC METHOD Test1()  AS STRING
     	 	
     RETURN "X# Test1() called"	
     	
     STATIC METHOD Test2()  AS STRING
     	 	
     RETURN "X# Test2() called"	
      	
     	
     END CLASS 

 
END NAMESPACE


to make it easier to see what i mean i´ve attached both dlls.

regards
Karl-Heinz

static class "Functions" within a namespace

Posted: Mon Aug 06, 2018 8:24 pm
by Chris
Hi Karl-Heinz,

Yes, theoretically it is possible to make the compiler generate a Functions class only when it is really needed, but I am afraid this will add much complication to the compiler code, intellisense etc, to check if each referenced library does have such a class or not etc. Unless Robert thinks it's relatively easy to allow this...

Chris

static class "Functions" within a namespace

Posted: Mon Aug 06, 2018 8:40 pm
by FFF
Guys,
why has the compiler to use "Functions" ? It knows what is meant, so it could use whatever, e.g., "Others"... How many people will study the compiler output vs the many end coders?
Just a thought...
Karl

static class "Functions" within a namespace

Posted: Mon Aug 06, 2018 9:51 pm
by robert
Karl
We have chosen the Functions name to be compatible with Vulcan.
When we are fully self supporting we will most likely switch to another name that has no risk of conflicts, such as XSharp$Functions.

Robert

static class "Functions" within a namespace

Posted: Tue Aug 07, 2018 12:34 am
by Jamal
Hi,

I wish you guys just disassociate X# from Vulcan baggage for good. I doubt there are many Vulcan developers who actually use it.

Jamal

static class "Functions" within a namespace

Posted: Tue Aug 07, 2018 8:47 am
by Karl-Heinz
Guys,

ok, compatibility with Vulcan is a valid point. And yes, at least another name like "XSharp$Functions" would be a step forward.

JFTR: Based on the KHRFuncsLibX_2.dll content i´ve attached a C# compiled Dll - of course with a namespace class "Functions" ;-)


regards
Karl-Heinz