Bug 22526 – Strange type error for function pointer that references its own container

Status
NEW
Severity
normal
Priority
P3
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2021-11-19T03:55:07Z
Last change time
2024-12-13T19:19:22Z
Assigned to
No Owner
Creator
andy-hanson
Moved to GitHub: dmd#20009 →

Comments

Comment #0 by andy-hanson — 2021-11-19T03:55:07Z
``` 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.)
Comment #1 by robert.schadek — 2024-12-13T19:19:22Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/20009 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB