Bug 20178 – Add TypeInfo_Class/TypeInfo_Interface.isBaseOf (equivalent to C#/Java isAssignableFrom)

Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P1
Component
druntime
Product
D
Version
D2
Platform
All
OS
All
Creation time
2019-08-28T23:49:45Z
Last change time
2020-04-16T19:31:06Z
Keywords
pull
Assigned to
No Owner
Creator
Nathan S.

Comments

Comment #0 by n8sh.secondary — 2019-08-28T23:49:45Z
C# System.Type and Java java.lang.Class have `isAssignableFrom` to conveniently determine at runtime whether a class inherits from or implements another class or interface. Adding something similar to TypeInfo_Class and TypeInfo_Interface would be useful. The name "isAssignableFrom" would be familiar to people coming from C# or Java but is potentially misleading since since -- due to "alias this" and the ability to overload opAssign -- whether a value of type Y can be assigned to a variable of type X is not the same as asking if Y inherits from or implements X. The language "derives from" is used in the D specification so I'm suggesting "isDerivedFrom" swapping the receiver and argument relative to "isAssignableFrom."
Comment #1 by dlang-bot — 2019-08-29T00:09:32Z
@n8sh created dlang/druntime pull request #2770 "Give TypeInfo_Class/TypeInfo_Interface.isDerivedFrom like C#/Java isAssignableFrom" fixing this issue: - Fix Issue 20178 - Add TypeInfo_Class/TypeInfo_Interface.isDerivedFrom Equivalent to C#/Java isAssignableFrom with the argument swapped with the receiver. 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. https://github.com/dlang/druntime/pull/2770
Comment #2 by dlang-bot — 2020-04-16T19:31:06Z
dlang/druntime pull request #2770 "Give TypeInfo_Class/TypeInfo_Interface.isBaseOf like C#/Java isAssignableFrom" was merged into master: - bc10972b8e5d6c70a9fce3abcc598f6cf120f08d by Nathan Sashihara: 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. https://github.com/dlang/druntime/pull/2770