modeswitch multihelpers precedence problem
Original Reporter info from Mantis: sysrpl
-
Reporter name: Anthony Walter
Original Reporter info from Mantis: sysrpl
- Reporter name: Anthony Walter
Description:
I started adding {$modeswitch multihelpers} to some of my code and noticed a problem. It would seem that the SysUtils unit is defining type helpers for the string type and this led me to discover that multiple type helpers takes precedence over other helpers in a way that is conflicts with other pascal rules.
To demonstrate, if I have MyUnit.pas that defines a string type helper with EndsWith() and an IntToStr() function then consider the following code:
program Test;
uses
MyUnit, SysUtils;
begin
'hello'.EndsWith('lo'); // invokes MyUnit.TStringHelper.EndsWith()
IntToStr(12); // invokes SysUtils.IntToStr()
end.
But if I reverse the uses order:
program Test;
uses
SysUtils, MyUnit;
begin
'hello'.EndsWith('lo'); // invokes SysUtils.TStringHelper.EndsWith()
IntToStr(12); // invokes MyUnit.IntToStr()
end.
What should happen is that both examples use the function from the last unit in the uses clause. Using the example above with "uses SysUtils, MyUnit;" the following should happen:
'hello'.EndsWith('lo'); // invokes MyUnit.TStringHelper.EndsWith()
IntToStr(12); // invokes MyUnit.IntToStr()
I know some of you might see this as a small problem, but it's an inconstancy that can lead to a situation where the wrong methods will be called without being obvious. The standard has long been that when an identifier of the same name is is found, pascal will choose to identify the name as the one coming from the last matching unit in the uses clause. Multiple type helpers should follow this same rule.
Please discuss and if we all agree I will file this as a bug in mantis. Thanks.
Additional information:
The description of this issue was posted to the pascal mailings lists. It would seem the consensus was this is a bug and a report should be filed. In my opinion and echoes by a few others the behavior should be like with normal pascal rules. That is when a conflict is encountered the compiler should use the last unit's definition.
Mantis conversion info:
- Mantis ID: 36783
- Version: 3.3.1