www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 22526] New: Strange type error for function pointer that


          Issue ID: 22526
           Summary: Strange type error for function pointer that
                    references its own container
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: andy.pj.hanson gmail.com

alias Fn(T) = void function(FnContainer!T);

void fn(T)(FnContainer!T) {}

struct FnContainer(T) {
        Fn!T* fn;

void main() {
        Fn!int fnInt = &fn!int;
        Fn!string fnString = &fn!string;
        FnContainer!string a = FnContainer!string(&fnString);

When I run `dmd a.d`, it fails with:
a.d(12): Error: cannot implicitly convert expression `& fnString` of type `void
function(FnContainer!string)*` to `void function(FnContainer!int)*`

This code ought to compile since I explicitly requested a `FnContainer!string`.
It is incorrectly expecting the parameter to be a `Fn!int*`.

There is no error if the unused variable `fnInt` is removed.
There is also no error if the container has `Fn!T` instead of `Fn!T*`. (In my
case I actually want a function pointer pointer.)

Nov 18 2021