A cool feature introduced in Delphi 10.2 Tokyo: often [RSP-17326] with statements generate W1048 unsafe typecast warning – Embarcadero Technologies.
Only 2 upvotes, so I assume the “anti with
camp” people are finally winning (:
Notes:
- that not all with statements generate a
W1048
warning. It looks like the ones using local variables don’t, but parameters, properties and fields to. - when generated, they are always of this form:
W1048 Unsafe typecast of '%s' to 'Pointer'
- I only found one other public report searching for “w1048” “to ‘Pointer'” – Google Search:
Quoted from the bug-report (as they cannot be archived in the wayback machine)
with statements generate W1048 unsafe typecast warning
Details
Type:Bug
Status:Reported
Priority:Major
Resolution:Unresolved Affects Version/s:10.2 Tokyo Fix Version/s:None Component/s:Delphi Compiler Labels: None
Build No: 25.0.25948.9960 Platform: All Language Version: English Edition: Enterprise InternalID: RS-82298 InternalStatus: ValidationDescription
All with statements generate this warning. I am on board with the theory that all with statements are inherently somewhat unsafe, but with 1.5 million lines of legacy code (and over 500 new warnings), I would significantly prefer to have a separate warning for with statements.
As it happens I would like to go through and do this work, especially if we can have refactoring to restore non-with code – see RSP-13978. BUT, Godzilla is generating new extra warnings (including unsafe typecasts) in this legacy code and I would prefer to be able to attack these first and attend to with statements later.Activity
Comments
–jeroen
Jason Sprenger requested more info in order to validate the issue and commented: Not any code involving “with” statements produces an unsafe typecast warning.
For instance,
What sort of source involving “with” statements is generating these warnings for you?
With this information our development team can consider addressing your particular circumstance.