Thread overview | ||||||
---|---|---|---|---|---|---|
|
November 14, 2009 [Issue 3511] New: ref return property confused with property setter | ||||
---|---|---|---|---|
| ||||
http://d.puremagic.com/issues/show_bug.cgi?id=3511 Summary: ref return property confused with property setter Product: D Version: 2.036 Platform: Other OS/Version: Linux Status: NEW Keywords: rejects-valid Severity: normal Priority: P2 Component: DMD AssignedTo: nobody@puremagic.com ReportedBy: k-foley@onu.edu --- Comment #0 from Kyle Foley <k-foley@onu.edu> 2009-11-14 12:56:09 PST --- import std.stdio; struct A { private int _prop = 42; ref int property() { return _prop; } //void property(in int rhs) { _prop = rhs; } } int main(string[] args) { A a; writeln( a.property ); a.property = 23; // produces the error below /* Error: function refProperty.A.property () is not callable using argument types (int) Error: expected 0 arguments, not 1 for non-variadic function type ref int() */ writeln( a.property ); return 0; } --- I think this is a bug, but it may actually be a "feature". -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
February 05, 2010 [Issue 3511] ref return property confused with property setter | ||||
---|---|---|---|---|
| ||||
Posted in reply to Kyle Foley | http://d.puremagic.com/issues/show_bug.cgi?id=3511 Witold Baryluk <baryluk@smp.if.uj.edu.pl> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |baryluk@smp.if.uj.edu.pl --- Comment #1 from Witold Baryluk <baryluk@smp.if.uj.edu.pl> 2010-02-05 05:46:48 PST --- Yes, this is interesting "feature" but I think it should be marked to be so, be some kind of attributed: struct A { private int x_ = 42; @property @ref_getter_as_setter ref int x() { return x_; } } It still can be allowed without this properties, but then compile should emit warning. What do you think? -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
February 05, 2010 [Issue 3511] ref return property confused with property setter | ||||
---|---|---|---|---|
| ||||
Posted in reply to Kyle Foley | http://d.puremagic.com/issues/show_bug.cgi?id=3511 --- Comment #2 from Kyle Foley <k-foley@onu.edu> 2010-02-05 14:30:22 PST --- (In reply to comment #1) > Yes, this is interesting "feature" but I think it should be marked to be so, be some kind of attributed: > > > struct A { > private int x_ = 42; > > @property > @ref_getter_as_setter > ref int x() { return x_; } > } > > It still can be allowed without this properties, but then compile should emit warning. > > What do you think? I think that properties in general suck. The only thing I want is the syntax for omitting the parentheses when calling a function without arguments. I don't want the compiler transforming something like "a.property = 42;" into "a.property(42);". It seems so bizarre to me, but I must be in the minority. I would solve this problem by either introducing reference types like C++ or allowing alias this to alias to a dereferenced pointer: struct Ref(T) { T* _ref; alias *_ref this; this(ref T rhs) { _ref = &rhs; } } Then I could implement properties by doing something like this: struct A { private int _prop = 42; PropertyHelper property() { return PropertyHelper(_prop); } struct PropertyHelper { private int _p; private Ref!int _reference; alias _p this; // aliased to a copy this(ref int rhs) : _reference(rhs); // meh, I don't know how to do this in D { writeln("Log: called the getter"); _p = rhs; // note this is a copy } void opAssign(in int rhs) { writeln("Log: called the setter"); _reference = rhs; } } } But a problem could be that when doing "auto x = a.property;" the type of x would be PropertyHelper. I mean, personally I would just do int getProperty(); and void setProperty(int); and be done with it. Anyways, I think we need to provide more general functionality from the compiler so that cool things can be done with libraries (e.g. letting alias this do more like the example above). -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
June 22, 2011 [Issue 3511] ref return property confused with property setter | ||||
---|---|---|---|---|
| ||||
Posted in reply to Kyle Foley | http://d.puremagic.com/issues/show_bug.cgi?id=3511 Walter Bright <bugzilla@digitalmars.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |RESOLVED CC| |bugzilla@digitalmars.com Resolution| |FIXED --- Comment #5 from Walter Bright <bugzilla@digitalmars.com> 2011-06-22 00:16:11 PDT --- https://github.com/D-Programming-Language/dmd/commit/3d5f405babe65f65ebd2e1c92e9b84ee30eaee8d https://github.com/D-Programming-Language/dmd/commit/84e95255e51d02512935560de3424410ace1ba67 -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
Copyright © 1999-2021 by the D Language Foundation