C1.foo correctly reports error with wrong implicit conversion from TypeInfo to inout(TypeInfo), but C2.foo doesn't.
class B {
inout(TypeInfo) foo() nothrow pure inout {
return null;
}
}
class C1 {
/*override*/ inout(TypeInfo) foo() inout {
return typeid(Object); // error, correct
}
}
class C2 : B {
override inout(TypeInfo) foo() inout {
return typeid(Object); // no error, BUG
}
}
Comment #1 by henning — 2013-07-28T14:14:44Z
Reduced:
class C {
inout(TypeInfo) foo() pure inout {
return typeid(Object);
}
}
The problem is that by using typeid(Object) you can get access to a global class instance (TypeInfo) in a pure function. And the result of pure functions can be casted to be inout. But in this case you didn't create the class instance by yourself. So only self-created TypeInfo-instances should be allowed to get casted. These are hard to detect though.
Comment #2 by robert.schadek — 2024-12-13T18:04:29Z