www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 4407] New: Catch wrong argument<->attribute assignments in methods

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

           Summary: Catch wrong argument<->attribute assignments in
                    methods
           Product: D
           Version: D1 & D2
          Platform: All
        OS/Version: All
            Status: NEW
          Keywords: diagnostic
          Severity: enhancement
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: bearophile_hugs eml.cc


--- Comment #0 from bearophile_hugs eml.cc 2010-06-29 18:15:53 PDT ---
This is related to bug 3878 , but it is meant to catch a different kind of bug.
In my code I have seen two times bugs like:


class Foo {
    int x, y;
    this(int x_, int y_) {
        this.x = x;
        y = y;

    }
}
void main() {}


In D.learn Byron Heads has found this bug:
http://www.digitalmars.com/webnews/newsgroups.php?art_group=digitalmars.D.learn&article_id=20354

this(string name, string id) {
    this._name = _name;
    this._id  = id;
}


So I think the D compiler has to catch such bugs, and refuse such assignments
in class/struct member functions.

Automatic code generation can sometimes generate useless assignments, but
catching common human bugs is more important. It's much simpler to fix code
generators than humans.

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



--- Comment #1 from bearophile_hugs eml.cc 2010-09-20 17:32:46 PDT ---
To keep the language semantics more uniform (instead of special-casing just in
methods), all redundant assignments may be flagged as errors:


void main() {
    int x;
    x = x; // error, redundant assignment
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Sep 20 2010
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4407



--- Comment #2 from bearophile_hugs eml.cc 2010-09-20 17:47:19 PDT ---
It's present among the Semantic Errors of Java code in the Google Web Toolkit
too:

http://code.google.com/intl/en-EN/webtoolkit/tools/codepro/doc/features/audit/audit_rules_com.instantiations.assist.eclipse.auditGroup.semanticErrors.html#com.instantiations.assist.eclipse.audit.redundantAssignment

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Sep 20 2010
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4407



--- Comment #3 from bearophile_hugs eml.cc 2010-10-01 16:57:39 PDT ---
Another similar class of bugs, suggested by JimBob:


class Foo {
   int m_x;
   this(int x) {
       int m_x = x;
   }
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Oct 01 2010
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4407



--- Comment #4 from bearophile_hugs eml.cc 2011-07-11 10:03:16 PDT ---
One example of bug related to  x=x;  found inside the good QT libs:


PassRefPtr<Structure> 
Structure::getterSetterTransition(Structure* structure)
{
  ...
  RefPtr<Structure> transition = create(
    structure->storedPrototype(), structure->typeInfo());
  transition->m_propertyStorageCapacity = 
    structure->m_propertyStorageCapacity;
  transition->m_hasGetterSetterProperties = 
    transition->m_hasGetterSetterProperties;
  transition->m_hasNonEnumerableProperties = 
    structure->m_hasNonEnumerableProperties;
  transition->m_specificFunctionThrashCount = 
    structure->m_specificFunctionThrashCount;
  ...
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jul 11 2011
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4407


Andrej Mitrovic <andrej.mitrovich gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |dimitri.sabadie gmail.com


--- Comment #5 from Andrej Mitrovic <andrej.mitrovich gmail.com> 2012-12-20
15:03:53 PST ---
*** Issue 9080 has been marked as a duplicate of this issue. ***

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


Andrej Mitrovic <andrej.mitrovich gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |andrej.mitrovich gmail.com
         Resolution|                            |WONTFIX


--- Comment #6 from Andrej Mitrovic <andrej.mitrovich gmail.com> 2013-01-09
17:41:19 PST ---
Denied by Walter. A shame because this is a common user bug.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 09 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4407


Denis Shelomovskij <verylonglogin.reg gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |verylonglogin.reg gmail.com


--- Comment #7 from Denis Shelomovskij <verylonglogin.reg gmail.com> 2013-06-29
19:13:27 MSD ---
(In reply to comment #6)
 Denied by Walter. A shame because this is a common user bug.
Any comments about the reason? -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Jun 29 2013
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4407



--- Comment #8 from bearophile_hugs eml.cc 2013-06-29 10:04:25 PDT ---
(In reply to comment #7)

 Any comments about the reason?
If you don't receive answers here in a day or two, then you probably have to ask again in the main D newsgroup... -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Jun 29 2013