Bug 4407 – Catch wrong argument<->attribute assignments in methods
Status
RESOLVED
Resolution
WONTFIX
Severity
enhancement
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2010-06-29T18:15:00Z
Last change time
2015-06-09T05:10:43Z
Keywords
diagnostic
Assigned to
nobody
Creator
bearophile_hugs
Comments
Comment #0 by bearophile_hugs — 2010-06-29T18:15:53Z
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.
Comment #1 by bearophile_hugs — 2010-09-20T17:32:46Z
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
}
Comment #2 by bearophile_hugs — 2010-09-20T17:47:19Z
Comment #3 by bearophile_hugs — 2010-10-01T16:57:39Z
Another similar class of bugs, suggested by JimBob:
class Foo {
int m_x;
this(int x) {
int m_x = x;
}
}
Comment #4 by bearophile_hugs — 2011-07-11T10:03:16Z
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;
...
}
Comment #5 by andrej.mitrovich — 2012-12-20T15:03:53Z
*** Issue 9080 has been marked as a duplicate of this issue. ***
Comment #6 by andrej.mitrovich — 2013-01-09T17:41:19Z
Denied by Walter. A shame because this is a common user bug.
Comment #7 by verylonglogin.reg — 2013-06-29T08:13:27Z
(In reply to comment #6)
> Denied by Walter. A shame because this is a common user bug.
Any comments about the reason?
Comment #8 by bearophile_hugs — 2013-06-29T10:04:25Z
(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...