mdempsky / unconvert

Remove unnecessary type conversions from Go source
BSD 3-Clause "New" or "Revised" License
377 stars 26 forks source link

False positive with using loop variable as a pointer #62

Closed vendelin8 closed 1 year ago

vendelin8 commented 1 year ago

https://go.dev/play/p/Uu5xmbWdvDY

The workaround to this would be to change line 11 to:

        sTmp = string(s)
        ssPtr[i] = &sTmp

But this gives unnecessary conversion (unconvert)

dmitshur commented 1 year ago

Is it possible to use the workaround of changing line 11 to this instead?

s := s
ssPtr[i] := &s

Does that avoid unnecessary conversion (unconvert)?

vendelin8 commented 1 year ago

Yes, thank you. Works fine.