Repository: goplus/gop
Pull request #2017 (2024-11-15 22:14:51)

mini spec: Order of evaluation


Patch:
diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml
index 1647fd4c..ab059676 100644
--- a/.github/workflows/go.yml
+++ b/.github/workflows/go.yml
@@ -48,7 +48,7 @@ jobs:
       run: go test -v -coverprofile="coverage.txt" -covermode=atomic ./...
 
     - name: Codecov
-      uses: codecov/codecov-action@v5
+      uses: codecov/codecov-action@v4
       with:
         token: ${{ secrets.CODECOV_TOKEN }}
         slug: goplus/gop
diff --git a/.github/workflows/release-build.yml b/.github/workflows/release-build.yml
index a90318a7..6f10496b 100644
--- a/.github/workflows/release-build.yml
+++ b/.github/workflows/release-build.yml
@@ -19,7 +19,7 @@ jobs:
         python .github/workflows/check_goreleaser_config.py
 
     - name: Install Snapcraft
-      uses: samuelmeuli/action-snapcraft@v3
+      uses: samuelmeuli/action-snapcraft@v2
 
     - name: Checkout tag
       run: |
diff --git a/doc/spec-mini.md b/doc/spec-mini.md
index 0e0d1f24..7e018279 100644
--- a/doc/spec-mini.md
+++ b/doc/spec-mini.md
@@ -836,6 +836,43 @@ var a map[string]any = {"Monday": 1, "Sunday": 7}
 echo a
 ```
 
+### Order of evaluation
+
+At package level, [initialization dependencies]() determine the evaluation order of individual initialization expressions in [variable declarations](). Otherwise, when evaluating the [operands]() of an expression, assignment, or [return statement](#return-statements), all function calls, method calls, [receive operations](), and [binary logical operations](#logical-operators) are evaluated in lexical left-to-right order.
+
+For example, in the (function-local) assignment
+
+```go
+y[f()], ok = g(z || h(), i()+x[j()], <-c), k()
+```
+
+the function calls and communication happen in the order `f()`, `h()` (if z evaluates to false), `i()`, `j()`, `<-c`, `g()`, and `k()`. However, the order of those events compared to the evaluation and indexing of `x` and the evaluation of `y` and `z` is not specified, except as required lexically. For instance, `g` cannot be called before its arguments are evaluated.
+
+```go
+a := 1
+f := func() int { a++; return a }
+x := [a, f()]      // x may be [1, 2] or [2, 2]: evaluation order between a and f() is not specified
+m := {a: 1, a: 2}  // m may be {2: 1} or {2: 2}: evaluation order between the two map assignments is not specified
+n := {a: f()}      // n may be {2: 3} or {3: 3}: evaluation order between the key and the value is not specified
+```
+
+At package level, initialization dependencies override the left-to-right rule for individual initialization expressions, but not for operands within each expression:
+
+```go
+var a, b, c = f() + v(), g(), sqr(u()) + v()
+
+func f() int        { return c }
+func g() int        { return a }
+func sqr(x int) int { return x*x }
+
+// functions u and v are independent of all other variables and functions
+```
+
+The function calls happen in the order `u()`, `sqr()`, `v()`, `f()`, `v()`, and `g()`.
+
+Floating-point operations within a single expression are evaluated according to the associativity of the operators. Explicit parentheses affect the evaluation by overriding the default associativity. In the expression `x + (y + z)` the addition `y + z` is performed before adding `x`.
+
+
 ## Statements
 
 Statements control execution.
diff --git a/go.mod b/go.mod
index 4a815a6b..3a5d2782 100644
--- a/go.mod
+++ b/go.mod
@@ -4,7 +4,7 @@ go 1.18
 
 require (
 	github.com/fsnotify/fsnotify v1.8.0
-	github.com/goplus/gogen v1.16.3-0.20241112142719-46167891a7ee
+	github.com/goplus/gogen v1.16.2-0.20241108030022-38cdc04c7425
 	github.com/goplus/llgo v0.9.7
 	github.com/goplus/mod v0.13.12
 	github.com/qiniu/x v1.13.10
diff --git a/go.sum b/go.sum
index 41a6e1a4..f5a4f1c3 100644
--- a/go.sum
+++ b/go.sum
@@ -1,7 +1,7 @@
 github.com/fsnotify/fsnotify v1.8.0 h1:dAwr6QBTBZIkG8roQaJjGof0pp0EeF+tNV7YBP3F/8M=
 github.com/fsnotify/fsnotify v1.8.0/go.mod h1:8jBTzvmWwFyi3Pb8djgCCO5IBqzKJ/Jwo8TRcHyHii0=
-github.com/goplus/gogen v1.16.3-0.20241112142719-46167891a7ee h1:lwV/kdyMI18qF70vd+ur2/rAdmoA+Zy+c/btdDiiYt8=
-github.com/goplus/gogen v1.16.3-0.20241112142719-46167891a7ee/go.mod h1:6TQYbabXDF9LCdDkOOzHmfg1R4ENfXQ3XpHa9RhTSD8=
+github.com/goplus/gogen v1.16.2-0.20241108030022-38cdc04c7425 h1:sbzi0nY672ZJJCaNVez31tryu0otBL/5WfZ6UQ61M4I=
+github.com/goplus/gogen v1.16.2-0.20241108030022-38cdc04c7425/go.mod h1:6TQYbabXDF9LCdDkOOzHmfg1R4ENfXQ3XpHa9RhTSD8=
 github.com/goplus/llgo v0.9.7 h1:LRF2Fq9ts4QrVxOPZufexalbIoJ1oiBERjCWQ45wxbg=
 github.com/goplus/llgo v0.9.7/go.mod h1:5Fs+08NslqofJ7xtOiIXugkurYOoQvY02ZkFNWA1uEI=
 github.com/goplus/mod v0.13.12 h1:Trwk6j3i9VvBuW6/9ZxmkoFlEL2v3HKQu0Na1c6DAdw=


Test patch:
diff --git a/cl/compile_gop_test.go b/cl/compile_gop_test.go
index 04742bf2..be836b38 100644
--- a/cl/compile_gop_test.go
+++ b/cl/compile_gop_test.go
@@ -1597,36 +1597,3 @@ func main() {
 }
 `)
 }
-
-func TestEmbedField(t *testing.T) {
-	gopClTest(t, `package main
-
-type Info struct {
-	id int
-}
-type T struct {
-	Info
-	id string
-}
-func demo(t *T) {
-	t.id = "0"
-}
-func main() {
-}
-`, `package main
-
-type Info struct {
-	id int
-}
-type T struct {
-	Info
-	id string
-}
-
-func demo(t *T) {
-	t.id = "0"
-}
-func main() {
-}
-`)
-}