[Issue 3008] Members of non-lvalues (rvalues) can be assigned to.

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu Jul 30 13:10:29 PDT 2009


http://d.puremagic.com/issues/show_bug.cgi?id=3008





--- Comment #15 from Chad Joan <chadjoan at gmail.com>  2009-07-30 13:10:29 PDT ---
(In reply to comment #12)
> (In reply to comment #9)
> > You make it sound like we wouldn't be able to use structs anymore!
> > 
> > Not the case.  
> 
> What I mean is this:
> 
> original:
> 
> class C
> {
>   void foo();
> }
> 
> struct S
> {
>    C getValue() {...}  
> }
> 
> void main()
> {
>    S s;
>    s.getValue.foo(); // should be allowed, getValue does not return an rvalue
> }
> 
> new version (assume C is the same):
> 
> struct MyNiftyPointerTo(T)
> {
>   ...
> }
> 
> struct S
> {
>    MyNiftyPointerTo!(C) getValue() {...}
> }
> 
> void main()
> {
>   S s;
>   s.getValue.foo(); // oops, compiler says MyNiftyPointerTo!(C) is an rvalue
> because it's a struct.
> }
> 

Incorrect.

s is an lvalue (it isn't being returned)
s.getValue is an lvalue (pointer to some C's data, AKA a reference type)
s.getValue.foo() function call on an lvalue.  fine.

It's the same logic as in Jarrett's comment (#3).  s may be a value type, but
s.getValue returns a reference type (the class C).  It is the same thing as
dereferencing a pointer, only it's hidden by saying that C is a "reference"
type.  The only thing I'm unsure of is how hard it is to get the compiler to
recognize this.

> What I'm saying is you have no ability to make wrapper or extended builtin
> types because they are now always treated as rvalues even though their
> semantics are entirely lvalue-ish.  Maybe MyNiftyPointerTo!(C) connects to a
> remote object on a server, and invokes methods there.  You're saying this isn't
> a valuable enough extension to the type system for D to allow it?

It's not going away because MyNiftyPointerTo!(C).getValue is an lvalue.

But I'm going to answer the question anyways.  Even if this were a problem, I'd
say no.  Just type the extra line of code.  Being a little less lazy here will
pay off.  You are a programmer.  Unless you are mentally handicapped or had an
unfortunate accident that crippled your hands, you type REALLY FAST.  Even on a
bad day full of nasty symbols that require you to hold shift repeatedly you
still type really fast!  You probably don't debug complicated code nearly as
quickly.  So you can have a feature that will save you a fraction of a second
here and there by requiring less typing, or you can have an absence of a
feature that will save you a few hours here and there by preventing the
existence of bugs.  Take your pick.

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


More information about the Digitalmars-d-bugs mailing list