mdempsky / unconvert

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

Don't warn for type aliases #61

Open jdemeyer opened 1 year ago

jdemeyer commented 1 year ago

Consider

type foo = int

func testUnconvert() {
    var x int = 42
    _ = foo(x)
}

unconvert flags this as "unnecessary conversion". But when looking at that code, there may a good reason for the fake "conversion": it could be an implementation detail that foo and int are aliases, it could be that foo and int are used for different purposes.

A good example is a conversion from int32 to rune, which is how I discovered this. Those are aliases, but typically used to represent very different things. Honestly, I didn't even know that they were aliases, until I got those unconvert warnings.