[Issue 11858] New: Comparison of unconnected classes using `is` must be disallowed

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu Jan 2 07:49:38 PST 2014


https://d.puremagic.com/issues/show_bug.cgi?id=11858

           Summary: Comparison of unconnected classes using `is` must be
                    disallowed
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Keywords: accepts-invalid
          Severity: major
          Priority: P2
         Component: DMD
        AssignedTo: nobody at puremagic.com
        ReportedBy: verylonglogin.reg at gmail.com


--- Comment #0 from Denis Shelomovskij <verylonglogin.reg at gmail.com> 2014-01-02 19:49:31 MSK ---
Comparison of unconnected classes using `is` is definitely a mistake. If one
want to do such raw things for some reason, he has to cast to e.g. `Object` or
`void*` first. Currently such construction is allowed even in `@safe` code.

This code should compile:
---
class A { }
class B { }

void main()
{
    A a;
    B b;
    static assert(!__traits(compiles, a is b)); // fails
}
---

As a result of the issue it's to easy to make a mistake like `a.prop1 is b`
instead of `a.prop1.owner is b`. Also a refactoring of class hierarchy by
segregating subclasses becomes a nightmare as you get no errors from type
system in situations when you e.g. forget to change `find` predicate.

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list