This repository has been archived by the owner on Oct 12, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 426
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix Issue 20178 - Add TypeInfo_Class/TypeInfo_Interface.isBaseOf
Equivalent to C#/Java isAssignableFrom. Naming the method "isAssignableFrom" would be more familiar to people coming from C#/Java but is potentially misleading: "alias this" and overloadable opAssign mean that this would not actually indicate whether values of one type could be assigned to another. Adding qualifiers to rt.cast_ functions.
- Loading branch information
Showing
4 changed files
with
93 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// https://issues.dlang.org/show_bug.cgi?id=20178 | ||
|
||
interface I {} | ||
interface J : I {} | ||
class C1 : I {} | ||
class C2 : C1 {} | ||
class C3 : J {} | ||
|
||
void main() @nogc nothrow pure @safe | ||
{ | ||
assert(typeid(C1).isBaseOf(typeid(C1))); | ||
assert(typeid(C1).isBaseOf(typeid(C2))); | ||
|
||
assert(!typeid(C2).isBaseOf(typeid(C1))); | ||
assert(typeid(C2).isBaseOf(typeid(C2))); | ||
|
||
assert(!typeid(C1).isBaseOf(typeid(Object))); | ||
assert(!typeid(C2).isBaseOf(typeid(Object))); | ||
assert(typeid(Object).isBaseOf(typeid(C1))); | ||
assert(typeid(Object).isBaseOf(typeid(C2))); | ||
|
||
assert(typeid(I).isBaseOf(typeid(I))); | ||
assert(typeid(I).isBaseOf(typeid(J))); | ||
assert(typeid(I).isBaseOf(typeid(C1))); | ||
assert(typeid(I).isBaseOf(typeid(C2))); | ||
assert(typeid(I).isBaseOf(typeid(C3))); | ||
assert(!typeid(I).isBaseOf(typeid(Object))); | ||
|
||
assert(!typeid(J).isBaseOf(typeid(I))); | ||
assert(typeid(J).isBaseOf(typeid(J))); | ||
assert(!typeid(J).isBaseOf(typeid(C1))); | ||
assert(!typeid(J).isBaseOf(typeid(C2))); | ||
assert(typeid(J).isBaseOf(typeid(C3))); | ||
assert(!typeid(J).isBaseOf(typeid(Object))); | ||
} |