digitalmars.D.learn - property/opAddAssign problem
- teo (23/23) Dec 29 2009 Consider following:
 - Steven Schveighoffer (7/31) Dec 29 2009 This is part of the issue with properties that will be fixed with the
 - Steven Schveighoffer (8/44) Dec 29 2009 Eventually, marking Prop as a @property should also work (haven't tested...
 - teo (6/59) Dec 29 2009 Unfortunately it doesn't:
 - Steven Schveighoffer (4/20) Dec 29 2009 It will evenutally, probably within the next couple releases.
 
Consider following:
class A
{
  int m;
  void opAddAssign(int n) { m += n; }
}
class B
{
  A a;
  this() { a = new A; }
  A Prop() { return a; }
}
void main()
{
  B b = new B;
  b.Prop += 3;
}
I get a compilation error (dmd v2.037):
test.d(17): Error: 'b.Prop' is not a scalar, it is a A()
test.d(17): Error: incompatible types for ((b.Prop) += (3)): 'A()' and 
'int'
Am I doing something wrong, or is this a known issue with opAddAssign and/
or properties?
 Dec 29 2009
On Tue, 29 Dec 2009 09:01:38 -0500, teo <teo.ubuntu.remove yahoo.com>  
wrote:
 Consider following:
 class A
 {
   int m;
   void opAddAssign(int n) { m += n; }
 }
 class B
 {
   A a;
   this() { a = new A; }
   A Prop() { return a; }
 }
 void main()
 {
   B b = new B;
   b.Prop += 3;
 }
 I get a compilation error (dmd v2.037):
 test.d(17): Error: 'b.Prop' is not a scalar, it is a A()
 test.d(17): Error: incompatible types for ((b.Prop) += (3)): 'A()' and
 'int'
 Am I doing something wrong, or is this a known issue with opAddAssign  
 and/
 or properties?
This is part of the issue with properties that will be fixed with the  
 property annotation.
try
b.Prop() += 3;
-Steve
 Dec 29 2009
On Tue, 29 Dec 2009 09:10:14 -0500, Steven Schveighoffer <schveiguy yahoo.com> wrote:On Tue, 29 Dec 2009 09:01:38 -0500, teo <teo.ubuntu.remove yahoo.com> wrote:Eventually, marking Prop as a property should also work (haven't tested it, it may work now): property A Prop() { return a; } ... b.Prop += 3; // compiles -SteveConsider following: class A { int m; void opAddAssign(int n) { m += n; } } class B { A a; this() { a = new A; } A Prop() { return a; } } void main() { B b = new B; b.Prop += 3; } I get a compilation error (dmd v2.037): test.d(17): Error: 'b.Prop' is not a scalar, it is a A() test.d(17): Error: incompatible types for ((b.Prop) += (3)): 'A()' and 'int' Am I doing something wrong, or is this a known issue with opAddAssign and/ or properties?This is part of the issue with properties that will be fixed with the property annotation. try b.Prop() += 3;
 Dec 29 2009
On Tue, 29 Dec 2009 09:12:15 -0500, Steven Schveighoffer wrote:On Tue, 29 Dec 2009 09:10:14 -0500, Steven Schveighoffer <schveiguy yahoo.com> wrote:Thanks. This trick works, but it looks a bit weird.On Tue, 29 Dec 2009 09:01:38 -0500, teo <teo.ubuntu.remove yahoo.com> wrote:Consider following: class A { int m; void opAddAssign(int n) { m += n; } } class B { A a; this() { a = new A; } A Prop() { return a; } } void main() { B b = new B; b.Prop += 3; } I get a compilation error (dmd v2.037): test.d(17): Error: 'b.Prop' is not a scalar, it is a A() test.d(17): Error: incompatible types for ((b.Prop) += (3)): 'A()' and 'int' Am I doing something wrong, or is this a known issue with opAddAssign and/ or properties?This is part of the issue with properties that will be fixed with the property annotation. try b.Prop() += 3;Eventually, marking Prop as a property should also work (haven't tested it, it may work now): property A Prop() { return a; } ... b.Prop += 3; // compiles -SteveUnfortunately it doesn't: test.d(17): Error: 'b.Prop' is not a scalar, it is a property A() test.d(17): Error: incompatible types for ((b.Prop) += (3)): ' property A ()' and 'int'
 Dec 29 2009
On Tue, 29 Dec 2009 13:44:18 -0500, teo <teo.ubuntu.remove yahoo.com> wrote:On Tue, 29 Dec 2009 09:12:15 -0500, Steven Schveighoffer wrote:It will evenutally, probably within the next couple releases. -SteveEventually, marking Prop as a property should also work (haven't tested it, it may work now): property A Prop() { return a; } ... b.Prop += 3; // compiles -SteveUnfortunately it doesn't: test.d(17): Error: 'b.Prop' is not a scalar, it is a property A() test.d(17): Error: incompatible types for ((b.Prop) += (3)): ' property A ()' and 'int'
 Dec 29 2009








 
 
 
 "Steven Schveighoffer" <schveiguy yahoo.com>