www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 8161] New: -property should give an error for invalid property functions

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8161

           Summary: -property should give an error for invalid property
                    functions
           Product: D
           Version: unspecified
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: jmdavisProg gmx.com



PDT ---
This code compiles with -property:

struct S
{
     property void prop()
    {
    }
}

void main()
{
}


It makes no sense that it would. prop returns nothing, so it can't be used as a
getter, and it takes nothing, so it can't be used as a setter. Neither

S s;
auto a = s.prop;

nor

s.prop = a;

would compile, so there's no point in letting prop compile with  property.
Another example would be a function like

struct S
{
     property void prop(int a, int b)
    {
    }
}

It can't possibly be used as a property function either. I'd argue that any
such function should be considered an error as long as it's marked as  property
and the -property flag is used.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
May 29 2012
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8161





 This code compiles with -property:
 
 struct S
 {
      property void prop()
     {
     }
 }
 
 void main()
 {
 }
 
 
 It makes no sense that it would.
I can agree.
 Another example would be a function like
 
 struct S
 {
      property void prop(int a, int b)
     {
     }
 }
 
 It can't possibly be used as a property function either. I'd argue that any
 such function should be considered an error as long as it's marked as  property
 and the -property flag is used.
A property function has two parameters is now allowed for UFCS property setter. property foo(T)(T obj, int val) { ... } void main() { S s; s.foo = 1; // translated to .foo(s, 1), it's valid. } -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
May 29 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8161




PDT ---
 A  property function has two parameters is now allowed for UFCS property
 setter.
  property foo(T)(T obj, int val) { ... }
 void main() {
    S s;
    s.foo = 1;  // translated to .foo(s, 1), it's valid.
 }
Yeah, because that's a free function. It's valid to use it as a property, so it makes sense for it to compile with property. The example that I gave with two arguments was a member function, which already has the invisible this parameter, so it won't work as a property. The point is that any function which cannot be legally used as a property function should not compile when marked with property and compiled with -property. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
May 29 2012
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8161





 A  property function has two parameters is now allowed for UFCS property
 setter.
  property foo(T)(T obj, int val) { ... }
 void main() {
    S s;
    s.foo = 1;  // translated to .foo(s, 1), it's valid.
 }
Yeah, because that's a free function. It's valid to use it as a property, so it makes sense for it to compile with property. The example that I gave with two arguments was a member function, which already has the invisible this parameter, so it won't work as a property. The point is that any function which cannot be legally used as a property function should not compile when marked with property and compiled with -property.
OK. I got an understanding. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
May 29 2012