[Issue 22526] New: Strange type error for function pointer that references its own container
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Fri Nov 19 03:55:07 UTC 2021
https://issues.dlang.org/show_bug.cgi?id=22526
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 at puremagic.com
Reporter: andy.pj.hanson at 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.)
--
More information about the Digitalmars-d-bugs
mailing list