-
Notifications
You must be signed in to change notification settings - Fork 15.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Append field number to accessors if there is conflict #6169
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,44 @@ | |
|
||
class WrapperTypeSettersTest extends TestBase | ||
{ | ||
public function testConflictNormalVsWrapper() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It looks like both functions have been renamed with a number on the end. Is that necessary? Why not just rename one of them, and keep the other unchanged? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think that is necessary. One field may be added before the other, and we don't want to accidentally change which field user is calling. Consider the case if |
||
{ | ||
$m = new Foo\TestWrapperAccessorConflicts(); | ||
|
||
$m->setNormalVsWrapperValue1(1); | ||
$this->assertSame(1, $m->getNormalVsWrapperValue1()); | ||
|
||
$m->setNormalVsWrapperValue2(1); | ||
$this->assertSame(1, $m->getNormalVsWrapperValue2()); | ||
|
||
$wrapper = new Int32Value(["value" => 1]); | ||
$m->setNormalVsWrapper($wrapper); | ||
$this->assertSame(1, $m->getNormalVsWrapper()->getValue()); | ||
} | ||
|
||
public function testConflictNormalVsNormal() | ||
{ | ||
$m = new Foo\TestWrapperAccessorConflicts(); | ||
|
||
$m->setNormalVsNormalValue(1); | ||
$this->assertSame(1, $m->getNormalVsNormalValue()); | ||
|
||
$m->setNormalVsNormal(1); | ||
$this->assertSame(1, $m->getNormalVsNormal()); | ||
} | ||
|
||
public function testConflictWrapperVsWrapper() | ||
{ | ||
$m = new Foo\TestWrapperAccessorConflicts(); | ||
|
||
$m->setWrapperVsWrapperValueValue(1); | ||
$this->assertSame(1, $m->getWrapperVsWrapperValueValue()); | ||
|
||
$wrapper = new Int32Value(["value" => 1]); | ||
$m->setWrapperVsWrapperValue5($wrapper); | ||
$this->assertSame(1, $m->getWrapperVsWrapperValue5()->getValue()); | ||
} | ||
|
||
/** | ||
* @dataProvider gettersAndSettersDataProvider | ||
*/ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Appending the field number works for this example, but what if there was also a field named
normal_vs_wrapper_value_2
? I'm not suggesting that that is very likely, but WDYT about a more general solution to this problem that would guarantee no conflicts. For example, inside a class, create a container of names used for methods, and each time you generate a method, add it to the container, check for conflicts, and if there is a conflict, resolve it by appending an incrementing counter - keep incrementing until the name is unique. This would also cover any other possible cases of collision (I'm not sure if any other cases exist in PHP).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will forces us to delay generating all accessors until we have traversed all fields of the same message. I feel this will be quite complicate.
For now, we used the same approach in java (which also has the problem of conflict after renaming)
In future, we would like to introducing some rules for naming a field, like no field can be named as a prefix of another field.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, sgtm.