www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - template/nested functions bug

reply "John C" <johnch_atms hotmail.com> writes:
This code produces the following error: "function Test.ensure is a nested 
function and cannot be accessed from testMethod". (DMD 0.133 Windows XP SP2)

template toArray(T) {
    T[] toArray(T[] params ...) {
        return params.dup;
    }
}

class Test {
    private static int[] values_;

    static void testMethod() {
        ensure();
    }

    static void ensure() {
        if (values_.length == 0)
            values_ = .toArray!(int)(1, 2, 3);
    }
}

Obviously, ensure() isn't a nested function. The error can be eliminated by 
surrounding the code in ensure() in block. Looks like the parser is 
mismatching braces? 
Sep 30 2005
parent =?UTF-8?B?VGhvbWFzIEvDvGhuZQ==?= <thomas-dloop kuehne.cn> writes:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

John C schrieb:
 This code produces the following error: "function Test.ensure is a nested 
 function and cannot be accessed from testMethod". (DMD 0.133 Windows XP SP2)
 
 template toArray(T) {
     T[] toArray(T[] params ...) {
         return params.dup;
     }
 }
 
 class Test {
     private static int[] values_;
 
     static void testMethod() {
         ensure();
     }
 
     static void ensure() {
         if (values_.length == 0)
             values_ = .toArray!(int)(1, 2, 3);
     }
 }
 
 Obviously, ensure() isn't a nested function. The error can be eliminated by 
 surrounding the code in ensure() in block. Looks like the parser is 
 mismatching braces? 
Added to DStress as http://dstress.kuehne.cn/run/i/inline_15_A.d http://dstress.kuehne.cn/run/i/inline_15_B.d Thomas -----BEGIN PGP SIGNATURE----- iD8DBQFDQEbf3w+/yD4P9tIRAiZPAJ0YFLZ3vFGsaEkwkBuaDNftM741dQCgp+/v Ju++M+Rk/UFHw6hdIEsToBo= =P739 -----END PGP SIGNATURE-----
Oct 02 2005