www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 4152] New: Function alias forward reference error

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4152

           Summary: Function alias forward reference error
           Product: D
           Version: unspecified
          Platform: x86
        OS/Version: Windows
            Status: NEW
          Keywords: rejects-valid
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: bearophile_hugs eml.cc



This compiles and runs with no errors with dmd 2.044:


int fun(TElem)(TElem[] arr) { return 10; }
alias fun!(char) alternative; // LINE A
int alternative(int[] arr) { return 20; } // LINE B
void caller(TOp)(TOp op, char[] s) {
    assert(op(s) == 10);
}
void main() {
    caller(&alternative, cast(char[])"abc");
}



But if I swap the line A and B:


int fun(TElem)(TElem[] arr) { return 10; }
int alternative(int[] arr) { return 20; } // LINE B
alias fun!(char) alternative; // LINE A
void caller(TOp)(TOp op, char[] s) {
    assert(op(s) == 10);
}
void main() {
    caller(&alternative, cast(char[])"abc");
}


Then dmd 2.044 shows:
test.d(5): Error: cannot implicitly convert expression (s) of type char[] to
int[]
test.d(8): Error: template instance test.caller!(int function(int[] arr)) error
instantiating

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
May 03 2010
parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4152




Another case, maybe with a different cause:


struct Foo(alias f) {}
Foo!main baz;
void main() {}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Aug 22 2010