On Thursday, 24 March 2022 at 12:35:38 UTC tapi...@gmail.com wrote:
> Aha, sorry, the file order really matters here.
> But for this specified case, it should not.
>
> That's not right. I remembered in an issue thread, it is mentioned that
> the order should be
>
> 1. D is not ready (because it
Aha, sorry, the file order really matters here.
But for this specified case, it should not.
That's not right. I remembered in an issue thread, it is mentioned that the
order should be
1. D is not ready (because it depends on A)
2. A is ready, so it is initialized: it gets value 3.
4. B is
Thank you all for the quick replies and helpful comments. I opened an issue
in the go's issue tracker (https://github.com/golang/go/issues/51913).
On Thursday, 24 March 2022 at 13:23:14 UTC+1 Brian Candler wrote:
> Ugh, quoting got broken there.
>
> $ go run rewritten_f1.go f2.go
> Init A
>
Ugh, quoting got broken there.
$ go run rewritten_f1.go f2.go
Init A
Init B
Init C
1 4 3
$ go run f2.go rewritten_f1.go
Init A
Init B
Init C
1 2 1
Hopefully that will show properly.
--
You received this message because you are subscribed to the Google Groups
"golang-nuts" group.
To
On Thursday, 24 March 2022 at 12:15:16 UTC tapi...@gmail.com wrote:
> BTW, the rewritten version outputs
>
> Init A
> Init B
> Init C
> 1 4 3
>
> On my machine (go1.18 linux/amd64).
>
It depends on the order, and the OP was positing what happens when f2.go is
presented first to the
On Thursday, 24 March 2022 at 11:30:37 UTC tapi...@gmail.com wrote:
> > 2. A < D < B < C - happens when f2.go is passed first to the compiler.
> In this case, the *expected output *would be "1 2 1". However, the *actual
> output* is "1 2 3".
>
> This is not true by my understanding of the spec.
BTW, the rewritten version outputs
Init A
Init B
Init C
1 4 3
On my machine (go1.18 linux/amd64).
On Thursday, March 24, 2022 at 7:30:37 PM UTC+8 tapi...@gmail.com wrote:
> > 2. A < D < B < C - happens when f2.go is passed first to the compiler.
> In this case, the *expected output *would
> 2. A < D < B < C - happens when f2.go is passed first to the compiler. In
this case, the *expected output *would be "1 2 1". However, the *actual
output* is "1 2 3".
This is not true by my understanding of the spec.
https://go.dev/ref/spec#Package_initialization
If f2.go is passed first,
On Wed, Mar 23, 2022 at 2:01 PM Joao Carlos wrote:
>
> I'm currently observing a behavior in the package initialization that looks
> incompatible with the Go language specification.
> Let's consider the following two .go files which are in the same package
>
> f1.go
> package main
>
> var A int
Hi all,
I'm currently observing a behavior in the package initialization that looks
incompatible with the Go language specification.
Let's consider the following two .go files which are in the same package
*f1.go*
package main
var A int = 3
var B int = A + 1
var C int = A
10 matches
Mail list logo