Summary: Mutable references to const/immutable/shared classes
           Product: D
           Version: D2
          Platform: Other
        OS/Version: All
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: DMD

--- Comment #0 from Michel Fortin <> 2010-12-05 
17:40:02 EST ---
Created an attachment (id=840)
Enable const(Object)ref syntax and semantics (patch)

It is currently not possible in the type system to have a mutable reference to
a const/immutable/shared/inout class, the reference always has the same
modifiers as the class itself. This is suboptimal as it prevents generic
algorithms from treating classes like other types.

This proposal extends type expressions so you can optionally make the
references part of a class variable explicit:

    Object a = new Object;
    Object ref b = new Object; // same thing

This then allows modifiers to be applied separately to the reference as needed:

    const(Object)ref c = new Object;
    shared(const(Object)ref) d = new Object;
    shared(Object ref) d = new Object; // same as shared(Object)

Type Matching
Using type matching to remove the qualifiers will now remove qualifiers only on
the reference part, similar to what would happen with pointers. There's not way
to remove the qualifier on the class part currently. This affects the behaviour
of Phobos's Unqual template when used with class.

Object type mangling stays unchanged when the reference has the same modifiers
as the class itself. When the reference has a different modifiers than the
reference, the reference is added before the class as a 'X' prefixed with the
type modifiers. For instance: "xXyC6Object" denotes a const ('x') reference to
an immutable ('y') class.

Type modifiers for the reference are not reflected in TypeInfo. Perhaps this
should be added.

Attached is a patch to enable this based on DMD revision 780. Also, once this
path is applied, one trivial change is needed in Phobos to fix Rebindable's
unittest (ironic!). All other tests are passing.

Configure issuemail:
------- You are receiving this mail because: -------

Reply via email to