On Fri, Mar 18, 2022 at 4:53 PM 'Axel Wagner' via golang-nuts <golang-nuts@googlegroups.com> wrote: > > One thing to keep in mind is that Go development was incremental and was > done, from early on, by having multiple implementations. Incremental > processes often lead to different results than designing a language from a > blank slate. Ambiguities in the spec are often discovered only when someone > notices that implementations disagree and must be resolved somehow. Sometimes > that happens after Go 1 and the resolution must happen in a way that, as much > as possible, retains stability guarantees. So, it's not unsurprising if we > get non-obvious spec clauses such as this. > > Specifically, I can well imagine that this particular case arose, because it > was discovered after the fact that one implementation contained an > optimization to not evaluate the argument to `len`, while the other didn't > and the question of side-effects only arose when someone noticed. > > I don't really know the answer to your question. I can't think of anything > which would break. That being said, I also don't think it's something that > really needs "fixing", as it seems a pretty uncommon concern.
I don't think there's anything ambiguous here. The very first sentence here: https://go.dev/ref/spec#Constant_expressions says """" Constant expressions may contain only constant operands and are evaluated at compile time. """" f() does not fill that requirement for sure, it's not a constant operand and it cannot be evaluated at compile time (in the first approximation). TBH, I thought that it was all clear from my first answer in this thread. The compiler error confirms the specs. -j -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/CAA40n-UnTCRcqGoSobLKsuRt1wDBzUMp-0XXqa4NLSrPsGRqfg%40mail.gmail.com.