During my reading of the interp.flushAll method I noticed that it accidentally uses conditional evaluation. Because the && operator is "short-circuited", if any Flush() returns a non-nil error, then all of the following Flush()-es will be skipped. allGood will be false so the right-hand side of && will not be evaluated.
// Flush all output streams as well as standard output. Report whether all
// streams were flushed successfully (logging error(s) if not).
func (p *interp) flushAll() bool {
allGood := true
for name, writer := range p.outputStreams {
allGood = allGood && p.flushWriter(name, writer)
}
if _, ok := p.output.(flusher); ok {
// User-provided output may or may not be flushable
allGood = allGood && p.flushWriter("stdout", p.output)
}
return allGood
}
Code changes are trivial but I'm not sure how to create a regression test as an interpreter "black box" test.
During my reading of the
interp.flushAll
method I noticed that it accidentally uses conditional evaluation. Because the&&
operator is "short-circuited", if anyFlush()
returns a non-nil error, then all of the followingFlush()
-es will be skipped.allGood
will be false so the right-hand side of&&
will not be evaluated.Code changes are trivial but I'm not sure how to create a regression test as an interpreter "black box" test.