Hacker News new | ask | show | jobs
by marcus_holmes 3021 days ago
Won't the compiler just ignore the "builder.String()" line unless the return value is actually used?
1 comments

Easy fix, use the anonymous variable;

    _ = builder.String()
The compiler should not optimize that out.
That's absolutely the same as the statement without assignment from a data flow POV. However, the compiler will likely not optimize it away since it would be too burdensome to proof that strings.Builder.String() does not have any side effects. The Go compiler prides itself with fast compilation speed, so I would not expect it to perform cross-package control/data flow analyses.