-
-
Notifications
You must be signed in to change notification settings - Fork 617
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Disallow initializing fields with themself
- Loading branch information
Showing
5 changed files
with
70 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
Initializing a field with itself has been deprecated | ||
|
||
This is to prevent a common mistake when typing a simple constructor, where a parameter name is misspelled: | ||
|
||
--- | ||
struct S | ||
{ | ||
int field; | ||
|
||
this(int feild) | ||
{ | ||
this.field = field; // equal to this.field = this.field | ||
} | ||
} | ||
--- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,7 @@ struct S | |
@disable this(this); | ||
this (scope ref inout S) inout | ||
{ | ||
this.b = b; | ||
this.b = 0; | ||
} | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/** | ||
REQUIRED_ARGS: -de | ||
TEST_OUTPUT: | ||
--- | ||
fail_compilation/ctor_self_assignment.d(17): Deprecation: cannot initialize field `location` with itself | ||
fail_compilation/ctor_self_assignment.d(15): did you mean to use parameter `locaction`? | ||
--- | ||
*/ | ||
// https://forum.dlang.org/post/[email protected] | ||
|
||
alias Location = int; | ||
|
||
struct Node | ||
{ | ||
this(Location locaction, uint f) | ||
{ | ||
this.location = location; | ||
this.f = f; | ||
} | ||
|
||
Location location; | ||
uint f; | ||
} |