Skip to content

Commit

Permalink
Merge branch 'master' into closure
Browse files Browse the repository at this point in the history
  • Loading branch information
rcoreilly authored Jul 19, 2024
2 parents 3cccd72 + c32b3ec commit 6c2ac63
Show file tree
Hide file tree
Showing 192 changed files with 1,133 additions and 3,213 deletions.
9 changes: 9 additions & 0 deletions _test/assign19.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package main

func main() {
a, b, c := 1, 2
_, _, _ = a, b, c
}

// Error:
// _test/assign19.go:4:2: cannot assign 2 values to 3 variables
23 changes: 23 additions & 0 deletions _test/issue-1640.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package main

import (
"errors"
)

func ShortVariableDeclarations() (i int, err error) {
r, err := 1, errors.New("test")
i = r
return
}

func main() {
_, er := ShortVariableDeclarations()
if er != nil {
println("ShortVariableDeclarations ok")
} else {
println("ShortVariableDeclarations not ok")
}
}

// Output:
// ShortVariableDeclarations ok
4 changes: 2 additions & 2 deletions extract/extract.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ func init() {
if W.WString == nil {
return ""
}
{{end -}}
{{$m.Ret}} W.W{{$m.Name}}{{$m.Arg}}
{{end}}
{{- $m.Ret}} W.W{{$m.Name}}{{$m.Arg -}}
}
{{end}}
{{end}}
Expand Down
10 changes: 9 additions & 1 deletion interp/cfg.go
Original file line number Diff line number Diff line change
Expand Up @@ -647,6 +647,14 @@ func (interp *Interpreter) cfg(root *node, sc *scope, importPath, pkgName string
sbase = len(n.child) - n.nright
}

// If len(RHS) > 1, each node must be single-valued, and the nth expression
// on the right is assigned to the nth operand on the left, so the number of
// nodes on the left and right sides must be equal
if n.nright > 1 && n.nright != n.nleft {
err = n.cfgErrorf("cannot assign %d values to %d variables", n.nright, n.nleft)
return
}

wireChild(n)
for i := 0; i < n.nleft; i++ {
dest, src := n.child[i], n.child[sbase+i]
Expand Down Expand Up @@ -681,7 +689,7 @@ func (interp *Interpreter) cfg(root *node, sc *scope, importPath, pkgName string
if dest.typ.incomplete {
return
}
if sc.global {
if sc.global || sc.isRedeclared(dest) {
// Do not overload existing symbols (defined in GTA) in global scope.
sym, _, _ = sc.lookup(dest.ident)
}
Expand Down
1 change: 1 addition & 0 deletions interp/interp_consistent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ func TestInterpConsistencyBuild(t *testing.T) {
file.Name() == "assign11.go" || // expect error
file.Name() == "assign12.go" || // expect error
file.Name() == "assign15.go" || // expect error
file.Name() == "assign19.go" || // expect error
file.Name() == "bad0.go" || // expect error
file.Name() == "break0.go" || // expect error
file.Name() == "cont3.go" || // expect error
Expand Down
7 changes: 7 additions & 0 deletions interp/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -1413,6 +1413,13 @@ func call(n *node) {
}
runCfg(def.child[3].start, nf, def, n)

// Set return values
for i, v := range rvalues {
if v != nil {
v(f).Set(nf.data[i])
}
}

// Handle branching according to boolean result
if fnext != nil && !nf.data[0].Bool() {
return fnext
Expand Down
8 changes: 8 additions & 0 deletions interp/scope.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,14 @@ func (s *scope) lookup(ident string) (*symbol, int, bool) {
return nil, 0, false
}

func (s *scope) isRedeclared(n *node) bool {
if !isNewDefine(n, s) {
return false
}
// Existing symbol in the scope indicates a redeclaration.
return s.sym[n.ident] != nil
}

func (s *scope) rangeChanType(n *node) *itype {
if sym, _, found := s.lookup(n.child[1].ident); found {
if t := sym.typ; len(n.child) == 3 && t != nil && (t.cat == chanT || t.cat == chanRecvT) {
Expand Down
12 changes: 3 additions & 9 deletions stdlib/go1_21_compress_flate.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 1 addition & 3 deletions stdlib/go1_21_compress_zlib.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 5 additions & 15 deletions stdlib/go1_21_container_heap.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 4 additions & 12 deletions stdlib/go1_21_context.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 3 additions & 9 deletions stdlib/go1_21_crypto.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 8 additions & 24 deletions stdlib/go1_21_crypto_cipher.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 2 additions & 6 deletions stdlib/go1_21_crypto_elliptic.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 3 additions & 9 deletions stdlib/go1_21_database_sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 6c2ac63

Please sign in to comment.