nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: goplus/gop
Pull request #1664 (2024-01-24 14:01:26)

x/build: use modfile.ClassExt


Patch:
diff --git a/x/build/build.go b/x/build/build.go
index 0b99626e..10fae033 100644
--- a/x/build/build.go
+++ b/x/build/build.go
@@ -21,7 +21,6 @@ import (
 	"fmt"
 	goast "go/ast"
 	"go/types"
-	"path"
 	"path/filepath"
 
 	"github.com/goplus/gop/ast"
@@ -31,6 +30,7 @@ import (
 	"github.com/goplus/gop/token"
 	"github.com/goplus/gox"
 	"github.com/goplus/gox/packages"
+	"github.com/goplus/mod/modfile"
 )
 
 type Class = cl.Class
@@ -76,7 +76,7 @@ func (p *Package) ToAst() *goast.File {
 }
 
 func ClassKind(fname string) (isProj, ok bool) {
-	ext := path.Ext(fname)
+	ext := modfile.ClassExt(fname)
 	switch ext {
 	case ".gmx":
 		return true, true


Test patch:
diff --git a/x/build/build_test.go b/x/build/build_test.go
index 116776eb..b09985c5 100644
--- a/x/build/build_test.go
+++ b/x/build/build_test.go
@@ -44,6 +44,7 @@ func init() {
 	build.RegisterClassFileType(".tspx", "MyGame", []*build.Class{
 		{Ext: ".tspx", Class: "Sprite"},
 	}, "github.com/goplus/gop/cl/internal/spx")
+	build.RegisterClassFileType("_yap.gox", "App", nil, "github.com/goplus/yap")
 }
 
 func gopClTest(t *testing.T, gopcode interface{}, expected string) {
@@ -76,6 +77,7 @@ func TestKind(t *testing.T) {
 	testKind(t, "main.gmx", true, true)
 	testKind(t, "Cat.tspx", false, true)
 	testKind(t, "main.tspx", true, true)
+	testKind(t, "blog_yap.gox", true, true)
 }
 
 func TestGop(t *testing.T) {
Repository: goplus/gop
Pull request #1670 (2024-01-25 14:03:28)

TestOverloadNamed


Patch:
diff --git a/cl/internal/overload/bar/bar.go b/cl/internal/overload/bar/bar.go
new file mode 100644
index 00000000..b675663b
--- /dev/null
+++ b/cl/internal/overload/bar/bar.go
@@ -0,0 +1,33 @@
+package bar
+
+const GopPackage = true
+
+type M = map[string]any
+
+type basetype interface {
+	string | int | bool | float64
+}
+
+type Var__0[T basetype] struct {
+	val T
+}
+
+func (p *Var__0[T]) Value() T {
+	return p.val
+}
+
+type Var__1[T map[string]any] struct {
+	val T
+}
+
+func (p *Var__1[T]) Value() T {
+	return p.val
+}
+
+func Gopx_Var_Cast__0[T basetype]() *Var__0[T] {
+	return new(Var__0[T])
+}
+
+func Gopx_Var_Cast__1[T map[string]any]() *Var__1[T] {
+	return new(Var__1[T])
+}


Test patch:
diff --git a/cl/compile_test.go b/cl/compile_test.go
index 031ee2e0..6889a30b 100644
--- a/cl/compile_test.go
+++ b/cl/compile_test.go
@@ -5140,3 +5140,70 @@ func main() {
 }
 `)
 }
+
+func TestOverloadNamed(t *testing.T) {
+	gopClTest(t, `
+import "github.com/goplus/gop/cl/internal/overload/bar"
+
+var a bar.Var[int]
+var b bar.Var[bar.M]
+c := bar.Var(string)
+d := bar.Var(bar.M)
+`, `package main
+
+import "github.com/goplus/gop/cl/internal/overload/bar"
+
+var a bar.Var__0[int]
+var b bar.Var__1[map[string]any]
+
+func main() {
+	c := bar.Gopx_Var_Cast__0[string]()
+	d := bar.Gopx_Var_Cast__1[map[string]any]()
+}
+`)
+}
+
+func TestMixedOverloadNamed(t *testing.T) {
+	gopMixedClTest(t, "main", `package main
+
+const GopPackage = true
+
+type M = map[string]any
+
+type basetype interface {
+	string | int | bool | float64
+}
+
+type Var__0[T basetype] struct {
+	val T
+}
+
+type Var__1[T map[string]any] struct {
+	val T
+}
+
+func Gopx_Var_Cast__0[T basetype]() *Var__0[T] {
+	return new(Var__0[T])
+}
+
+func Gopx_Var_Cast__1[T map[string]any]() *Var__1[T] {
+	return new(Var__1[T])
+}
+`, `
+var a Var[int]
+var b Var[M]
+c := Var(string)
+d := Var(M)
+`, `package main
+
+var a Var__0[int]
+var b Var__1[map[string]interface {
+}]
+
+func main() {
+	c := Gopx_Var_Cast__0[string]()
+	d := Gopx_Var_Cast__1[map[string]interface {
+	}]()
+}
+`)
+}
Repository: goplus/gop
Pull request #1683 (2024-01-28 18:12:31)

doc: unit-test


Patch:
diff --git a/doc/classfile.md b/doc/classfile.md
index e4df6647..715c0e5d 100644
--- a/doc/classfile.md
+++ b/doc/classfile.md
@@ -28,10 +28,10 @@ func foo(v int) int {
 Then you can create a `foo_test.gox` file to test it (see [unit-test/foo_test.gox](testdata/unit-test/foo_test.gox)):
 
 ```go
-if v := foo(50); v == 100 {
-	t.log "test foo(50) ok"
+if v := foo(50); v != 100 {
+	t.error "foo(50) ret: ${v}"
 } else {
-	t.error "foo() ret: ${v}"
+	t.log "test foo(50) ok"
 }
 
 t.run "foo -10", t => {


Test patch:
diff --git a/testdata/unit-test/foo_test.gox b/testdata/unit-test/foo_test.gox
index 4e238df3..b2482077 100644
--- a/testdata/unit-test/foo_test.gox
+++ b/testdata/unit-test/foo_test.gox
@@ -1,7 +1,7 @@
-if v := foo(50); v == 100 {
-	t.log "test foo(50) ok"
+if v := foo(50); v != 100 {
+	t.error "foo(50) ret: ${v}"
 } else {
-	t.error "foo() ret: ${v}"
+	t.log "test foo(50) ok"
 }
 
 t.run "foo -10", t => {
Repository: goplus/gop
Pull request #1685 (2024-01-29 00:51:52)

classfile: unit test


Patch:
diff --git a/doc/classfile.md b/doc/classfile.md
index 715c0e5d..6404498d 100644
--- a/doc/classfile.md
+++ b/doc/classfile.md
@@ -15,7 +15,7 @@ Go+ introduces `classfile` to abstract domain knowledge.
 
 ### classfile: Unit Test
 
-Go+ has built-in support for a classfile to simplify unit testing. This classfile has the file suffix `_test.gox`.
+Go+ has a built-in classfile to simplify unit testing. This classfile has the file suffix `_test.gox`.
 
 Suppose you have a function named `foo`:
 
@@ -25,13 +25,11 @@ func foo(v int) int {
 }
 ```
 
-Then you can create a `foo_test.gox` file to test it (see [unit-test/foo_test.gox](testdata/unit-test/foo_test.gox)):
+Then you can create a `foo_test.gox` file to test it (see [unit-test/foo_test.gox](../testdata/unit-test/foo_test.gox)):
 
 ```go
 if v := foo(50); v != 100 {
 	t.error "foo(50) ret: ${v}"
-} else {
-	t.log "test foo(50) ok"
 }
 
 t.run "foo -10", t => {


Test patch:
diff --git a/testdata/unit-test/foo_test.gox b/testdata/unit-test/foo_test.gox
index b2482077..13f35792 100644
--- a/testdata/unit-test/foo_test.gox
+++ b/testdata/unit-test/foo_test.gox
@@ -1,7 +1,5 @@
 if v := foo(50); v != 100 {
 	t.error "foo(50) ret: ${v}"
-} else {
-	t.log "test foo(50) ok"
 }
 
 t.run "foo -10", t => {
Repository: goplus/gop
Pull request #1722 (2024-02-11 22:09:06)

testdata/gop-sample


Patch:
diff --git a/cl/expr.go b/cl/expr.go
index c970fb70..6aa0a865 100644
--- a/cl/expr.go
+++ b/cl/expr.go
@@ -120,11 +120,6 @@ func compileIdent(ctx *blockCtx, ident *ast.Ident, flags int) (pkg gox.PkgRef, k
 		goto find
 	}
 
-	// function alias
-	if compileFuncAlias(ctx, scope, ident, flags) {
-		return
-	}
-
 	// pkgRef object
 	if (flags & clIdentSelectorExpr) != 0 {
 		if name == "C" && len(ctx.clookups) > 0 {
@@ -139,6 +134,11 @@ func compileIdent(ctx *blockCtx, ident *ast.Ident, flags int) (pkg gox.PkgRef, k
 		}
 	}
 
+	// function alias
+	if compileFuncAlias(ctx, scope, ident, flags) {
+		return
+	}
+
 	// object from import . "xxx"
 	if compilePkgRef(ctx, gox.PkgRef{}, ident, flags, objPkgRef) {
 		return


Test patch:
diff --git a/testdata/__gop-sample/go.mod b/testdata/__gop-sample/go.mod
deleted file mode 100644
index 73330159..00000000
--- a/testdata/__gop-sample/go.mod
+++ /dev/null
@@ -1,5 +0,0 @@
-module gop-sample
-
-go 1.21.5
-
-toolchain go1.21.6
diff --git a/testdata/__gop-sample/a.gop b/testdata/gop-sample/a.gop
similarity index 100%
rename from testdata/__gop-sample/a.gop
rename to testdata/gop-sample/a.gop
diff --git a/testdata/__gop-sample/b.gop b/testdata/gop-sample/b.gop
similarity index 100%
rename from testdata/__gop-sample/b.gop
rename to testdata/gop-sample/b.gop
diff --git a/testdata/__gop-sample/cpkag/b/ab.gop b/testdata/gop-sample/cpkag/b/ab.gop
similarity index 100%
rename from testdata/__gop-sample/cpkag/b/ab.gop
rename to testdata/gop-sample/cpkag/b/ab.gop
diff --git a/testdata/__gop-sample/gop.mod b/testdata/gop-sample/go.mod
similarity index 52%
rename from testdata/__gop-sample/gop.mod
rename to testdata/gop-sample/go.mod
index 1b1598e6..c0f1743d 100644
--- a/testdata/__gop-sample/gop.mod
+++ b/testdata/gop-sample/go.mod
@@ -1,5 +1,3 @@
 module gop-sample
 
-go 1.21
-
-gop 1.1
+go 1.18
Repository: goplus/gop
Pull request #1724 (2024-02-12 01:00:15)

ParseFSFiles fix: support SaveAbsFile flag


Patch:
diff --git a/parser/parser_gop.go b/parser/parser_gop.go
index 34f549f2..54013c62 100644
--- a/parser/parser_gop.go
+++ b/parser/parser_gop.go
@@ -263,7 +263,14 @@ func ParseFiles(fset *token.FileSet, files []string, mode Mode) (map[string]*ast
 
 func ParseFSFiles(fset *token.FileSet, fs FileSystem, files []string, mode Mode) (map[string]*ast.Package, error) {
 	ret := map[string]*ast.Package{}
+	fabs := (mode & SaveAbsFile) != 0
+	if fabs {
+		mode &^= SaveAbsFile
+	}
 	for _, file := range files {
+		if fabs {
+			file, _ = fs.Abs(file)
+		}
 		f, err := ParseFSFile(fset, fs, file, nil, mode)
 		if err != nil {
 			return nil, err


Test patch:
diff --git a/parser/parserdir_test.go b/parser/parserdir_test.go
index d43bfcae..3bec85ac 100644
--- a/parser/parserdir_test.go
+++ b/parser/parserdir_test.go
@@ -25,6 +25,7 @@ import (
 	"syscall"
 	"testing"
 
+	"github.com/goplus/gop/parser/fsx"
 	"github.com/goplus/gop/parser/fsx/memfs"
 	"github.com/goplus/gop/parser/parsertest"
 	"github.com/goplus/gop/scanner"
@@ -68,7 +69,7 @@ func TestReadSource(t *testing.T) {
 
 func TestParseFiles(t *testing.T) {
 	fset := token.NewFileSet()
-	if _, err := ParseFiles(fset, []string{"/foo/bar/not-exists"}, PackageClauseOnly); err == nil {
+	if _, err := ParseFSFiles(fset, fsx.Local, []string{"/foo/bar/not-exists"}, PackageClauseOnly|SaveAbsFile); err == nil {
 		t.Fatal("ParseFiles failed: no error?")
 	}
 }
Repository: goplus/gop
Pull request #1739 (2024-02-13 14:42:36)

TestUnsafe goplus/gox#378


Patch:
diff --git a/go.mod b/go.mod
index d67977e1..e53c2f31 100644
--- a/go.mod
+++ b/go.mod
@@ -8,7 +8,7 @@ require (
 	github.com/goplus/gox v1.14.10
 	github.com/goplus/mod v0.13.5
 	github.com/qiniu/x v1.13.5
-	golang.org/x/tools v0.17.0
+	golang.org/x/tools v0.18.0
 )
 
 require (
@@ -16,7 +16,7 @@ require (
 	github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 // indirect
 	github.com/modern-go/reflect2 v1.0.2 // indirect
 	golang.org/x/mod v0.15.0 // indirect
-	golang.org/x/sys v0.16.0 // indirect
+	golang.org/x/sys v0.17.0 // indirect
 )
 
 retract v1.1.12
diff --git a/go.sum b/go.sum
index bebcbb3f..007e94b4 100644
--- a/go.sum
+++ b/go.sum
@@ -55,8 +55,9 @@ golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBc
 golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
 golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
 golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
-golang.org/x/sys v0.16.0 h1:xWw16ngr6ZMtmxDyKyIgsE93KNKz5HKmMa3b8ALHidU=
 golang.org/x/sys v0.16.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
+golang.org/x/sys v0.17.0 h1:25cE3gD+tdBA7lp7QfhuV+rJiE9YXTcS3VG1SqssI/Y=
+golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
 golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
 golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
 golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
@@ -75,6 +76,7 @@ golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtn
 golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
 golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=
 golang.org/x/tools v0.13.0/go.mod h1:HvlwmtVNQAhOuCjW7xxvovg8wbNq7LwfXh/k7wXUl58=
-golang.org/x/tools v0.17.0 h1:FvmRgNOcs3kOa+T20R1uhfP9F6HgG2mfxDv1vrx1Htc=
 golang.org/x/tools v0.17.0/go.mod h1:xsh6VxdV005rRVaS6SSAf9oiAqljS7UZUacMZ8Bnsps=
+golang.org/x/tools v0.18.0 h1:k8NLag8AGHnn+PHbl7g43CtqZAwG60vZkLqgyZgIHgQ=
+golang.org/x/tools v0.18.0/go.mod h1:GL7B4CwcLLeo59yx/9UWWuNOW1n3VZ4f5axWfML7Lcg=
 golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=


Test patch:
diff --git a/cl/compile_test.go b/cl/compile_test.go
index 6c5d68d5..6cd295c3 100644
--- a/cl/compile_test.go
+++ b/cl/compile_test.go
@@ -122,6 +122,24 @@ func gopClTestFS(t *testing.T, conf *cl.Config, fs parser.FileSystem, pkgname, e
 	}
 }
 
+func TestUnsafe(t *testing.T) {
+	gopClTest(t, `
+import "unsafe"
+
+println unsafe.Sizeof(0)
+`, `package main
+
+import (
+	"fmt"
+	"unsafe"
+)
+
+func main() {
+	fmt.Println(unsafe.Sizeof(0))
+}
+`)
+}
+
 func Test_CastSlice_Issue1240(t *testing.T) {
 	gopClTest(t, `
 type fvec []float64
Repository: goplus/gop
Pull request #1740 (2024-02-13 15:07:30)

TestErrUnsafe


Patch:
diff --git a/README.md b/README.md
index 6115ed5d..8448ffd2 100644
--- a/README.md
+++ b/README.md
@@ -185,13 +185,13 @@ all.bat
 
 * [yap: Yet Another Go/Go+ HTTP Web Framework](https://github.com/goplus/yap)
 
-### HTTP Test Framework
+### HTTP Test
 
 * [yaptest: HTTP Test Framework](https://github.com/goplus/yap/tree/main/ytest)
 
 ### DevOps tools
 
-* [Go+ DevOps Tools](https://github.com/xushiwei/gshexample?tab=readme-ov-file#gsh-example)
+* [Go+ DevOps Tools](https://github.com/goplus/gop/blob/main/doc/dsl-vs-sdf.md#demo-go-devops-tools)
 
 ### Data processing
 
diff --git a/go.mod b/go.mod
index e53c2f31..13d73da8 100644
--- a/go.mod
+++ b/go.mod
@@ -5,7 +5,7 @@ go 1.18
 require (
 	github.com/fsnotify/fsnotify v1.7.0
 	github.com/goplus/c2go v0.7.22
-	github.com/goplus/gox v1.14.10
+	github.com/goplus/gox v1.14.11
 	github.com/goplus/mod v0.13.5
 	github.com/qiniu/x v1.13.5
 	golang.org/x/tools v0.18.0
diff --git a/go.sum b/go.sum
index 007e94b4..ccdcb718 100644
--- a/go.sum
+++ b/go.sum
@@ -6,8 +6,9 @@ github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyT
 github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
 github.com/goplus/c2go v0.7.22 h1:TnOf6VJTvVKFhp8+zTP6POwJ894mdNGV7qKRYY1o2oY=
 github.com/goplus/c2go v0.7.22/go.mod h1:f3v+Td4JQwhToKfQK5tGvjMoMBrIR9IJjHNqzDC6NIE=
-github.com/goplus/gox v1.14.10 h1:fbcA/BzFqEOp28BQjt27UR3DkYYpT4uXObWxZXEDkbU=
 github.com/goplus/gox v1.14.10/go.mod h1:G7Hz+cAOUyJyN9pPHrpqhfQPDUtiJNmoRVTwoaQ9nw0=
+github.com/goplus/gox v1.14.11 h1:Wg1VfHv88n7DTjGpWutRhNykqd059YT565KrTVtyg0Y=
+github.com/goplus/gox v1.14.11/go.mod h1:6b6XYHmyiCevhwuEHcV/jzm7Z2FXLDBhuxgvkjceA+o=
 github.com/goplus/mod v0.13.5 h1:rEQ4UFmLKU1J5IK82DwC/sAKIhAMJZ2VbBrKU/k448c=
 github.com/goplus/mod v0.13.5/go.mod h1:PBGRYvD381NxJdeI+KyYHiDX9fgnDiuttzyCTG9LfHE=
 github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=


Test patch:
diff --git a/cl/error_msg_test.go b/cl/error_msg_test.go
index 4a4e1a58..be1e8271 100644
--- a/cl/error_msg_test.go
+++ b/cl/error_msg_test.go
@@ -72,6 +72,12 @@ func codeErrorTestAst(t *testing.T, pkgname, filename, msg, src string) {
 	}
 }
 
+func TestErrUnsafe(t *testing.T) {
+	codeErrorTest(t, `bar.gop:2:9: undefined: Sizeof`, `
+println Sizeof(0)
+`)
+}
+
 func TestErrLambdaExpr(t *testing.T) {
 	codeErrorTest(t,
 		"bar.gop:7:6: too few arguments in lambda expression\n\thave ()\n\twant (int, int)", `
Repository: goplus/gop
Pull request #1753 (2024-02-17 14:06:30)

test classfile: App.M()


Patch:
diff --git a/README.md b/README.md
index 2b8a4760..b92e844d 100644
--- a/README.md
+++ b/README.md
@@ -215,8 +215,6 @@ $ brew install goplus
 
 ### from source code
 
-For now, we suggest you install Go+ from source code.
-
 Note: Requires go1.18 or later
 
 ```bash


Test patch:
diff --git a/test/classfile.go b/test/classfile.go
index e432c0a5..ff549662 100644
--- a/test/classfile.go
+++ b/test/classfile.go
@@ -38,7 +38,7 @@ func (p *Case) initCase(t *testing.T) {
 	p.t = t
 }
 
-// T returns a *testing.T object.
+// T returns the *testing.T object .
 func (p Case) T() *testing.T { return p.t }
 
 // Run runs f as a subtest of t called name. It runs f in a separate goroutine
@@ -65,6 +65,9 @@ func (p *App) initApp(m *testing.M) {
 	p.m = m
 }
 
+// M returns the *testing.M object.
+func (p App) M() *testing.M { return p.m }
+
 // Gopt_App_TestMain is required by Go+ compiler as the entry of a Go+ testing project.
 func Gopt_App_TestMain(app interface{ initApp(m *testing.M) }, m *testing.M) {
 	app.initApp(m)
Repository: goplus/gop
Pull request #1757 (2024-02-19 02:11:45)

gsh: exec


Patch:
diff --git a/.gitignore b/.gitignore
index e4d9000f..4619940e 100644
--- a/.gitignore
+++ b/.gitignore
@@ -51,4 +51,3 @@ go-num/
 _todo*.go
 
 dist/
-gsh-exec/
diff --git a/doc/code-coverage.md b/doc/code-coverage.md
deleted file mode 100644
index e31270e4..00000000
--- a/doc/code-coverage.md
+++ /dev/null
@@ -1,4 +0,0 @@
-Go+ Unit Test: Code Coverage
-=====
-
-TODO


Test patch:
diff --git a/testdata/gsh-exec/exec.gsh b/testdata/gsh-exec/exec.gsh
new file mode 100644
index 00000000..dbd3a0ab
--- /dev/null
+++ b/testdata/gsh-exec/exec.gsh
@@ -0,0 +1,5 @@
+gop "run", "./foo"
+exec "gop run ./foo"
+exec "FOO=100 gop run ./foo"
+exec {"FOO": "101"}, "gop", "run", "./foo"
+exec "gop", "run", "./foo"
diff --git a/testdata/gsh-exec/foo/foo.gop b/testdata/gsh-exec/foo/foo.gop
new file mode 100644
index 00000000..3d38dfaf
--- /dev/null
+++ b/testdata/gsh-exec/foo/foo.gop
@@ -0,0 +1,8 @@
+import "os"
+
+foo := os.getenv("FOO")
+if foo != "" {
+	echo foo
+} else {
+	echo "FOO not found"
+}
Repository: goplus/gop
Pull request #1760 (2024-02-20 00:54:15)

cl: range.body use vblock for new scope


Patch:
diff --git a/cl/stmt.go b/cl/stmt.go
index 61dd7397..dd3a98ad 100644
--- a/cl/stmt.go
+++ b/cl/stmt.go
@@ -359,11 +359,13 @@ func compileRangeStmt(ctx *blockCtx, v *ast.RangeStmt) {
 	if pos == 0 {
 		pos = v.For
 	}
-	cb.RangeAssignThen(pos) // TODO: need NewScope for body
+	cb.RangeAssignThen(pos)
 	if len(defineNames) > 0 {
 		defNames(ctx, defineNames, cb.Scope())
 	}
+	cb.VBlock()
 	compileStmts(ctx, v.Body.List)
+	cb.End(v.Body)
 	cb.SetComments(comments, once)
 	setBodyHandler(ctx)
 	cb.End(v)


Test patch:
diff --git a/cl/compile_test.go b/cl/compile_test.go
index cf095522..fa168f38 100644
--- a/cl/compile_test.go
+++ b/cl/compile_test.go
@@ -4213,3 +4213,26 @@ func main() {
 `
 	gopClTestEx(t, &conf, "main", src, expected)
 }
+
+func TestRangeScope(t *testing.T) {
+	gopClTest(t, `
+ar := []int{100, 200}
+for k, v := range ar {
+	println(k, v, ar)
+	var k, v, ar int
+	println(ar, k, v)
+}
+`, `package main
+
+import "fmt"
+
+func main() {
+	ar := []int{100, 200}
+	for k, v := range ar {
+		fmt.Println(k, v, ar)
+		var k, v, ar int
+		fmt.Println(ar, k, v)
+	}
+}
+`)
+}
Repository: goplus/gop
Pull request #1772 (2024-02-23 00:51:03)

cl: record lambda scope


Patch:
diff --git a/cl/expr.go b/cl/expr.go
index 27e4f21d..3d66cd8e 100644
--- a/cl/expr.go
+++ b/cl/expr.go
@@ -859,6 +859,9 @@ func compileLambdaExpr(ctx *blockCtx, v *ast.LambdaExpr, sig *types.Signature) e
 	for _, v := range v.Rhs {
 		compileExpr(ctx, v)
 	}
+	if rec := ctx.recorder(); rec != nil {
+		rec.Scope(v, ctx.cb.Scope())
+	}
 	ctx.cb.Return(len(v.Rhs)).End(v)
 	return nil
 }
@@ -877,6 +880,9 @@ func compileLambdaExpr2(ctx *blockCtx, v *ast.LambdaExpr2, sig *types.Signature)
 		defNames(ctx, v.Lhs, cb.Scope())
 	}
 	compileStmts(ctx, v.Body.List)
+	if rec := ctx.recorder(); rec != nil {
+		rec.Scope(v, ctx.cb.Scope())
+	}
 	cb.End(v)
 	ctx.cb.SetComments(comments, once)
 	return nil


Test patch:
diff --git a/x/typesutil/info_test.go b/x/typesutil/info_test.go
index 17e59a56..87e083ba 100644
--- a/x/typesutil/info_test.go
+++ b/x/typesutil/info_test.go
@@ -1749,6 +1749,15 @@ func TestScopesInfo(t *testing.T) {
 		{`package p23; func _(){ sum := 0; for x <- [1, 3, 5, 7, 11, 13, 17] { sum = sum + x; c := sum; _ = c } }`, []string{
 			"file:", "func:sum", "for phrase:x", "block:c",
 		}},
+		{`package p23; func test(fn func(int)int){};func _(){test(func(x int) int { y := x*x; return y } ) }`, []string{
+			"file:test", "func:fn", "func:", "func:x y",
+		}},
+		{`package p24; func test(fn func(int)int){};func _(){test( x => x*x );}`, []string{
+			"file:test", "func:fn", "func:", "lambda:x",
+		}},
+		{`package p25; func test(fn func(int)int){};func _(){test( x => { y := x*x; return y } ) }`, []string{
+			"file:test", "func:fn", "func:", "lambda:x y",
+		}},
 	}
 
 	for _, test := range tests {
@@ -1789,6 +1798,10 @@ func TestScopesInfo(t *testing.T) {
 				kind = "range"
 			case *ast.ForPhraseStmt:
 				kind = "for phrase"
+			case *ast.LambdaExpr:
+				kind = "lambda"
+			case *ast.LambdaExpr2:
+				kind = "lambda"
 			default:
 				kind = fmt.Sprintf("<unknown node kind> %T", node)
 			}
Repository: goplus/gop
Pull request #1773 (2024-02-23 01:30:39)

ast: walk add *IndexListExpr


Patch:
diff --git a/ast/walk.go b/ast/walk.go
index 08874611..4ce089ff 100644
--- a/ast/walk.go
+++ b/ast/walk.go
@@ -136,6 +136,10 @@ func Walk(v Visitor, node Node) {
 		Walk(v, n.X)
 		Walk(v, n.Index)
 
+	case *IndexListExpr:
+		Walk(v, n.X)
+		walkExprList(v, n.Indices)
+
 	case *SliceExpr:
 		Walk(v, n.X)
 		if n.Low != nil {
diff --git a/cl/expr.go b/cl/expr.go
index 3d66cd8e..27e4f21d 100644
--- a/cl/expr.go
+++ b/cl/expr.go
@@ -859,9 +859,6 @@ func compileLambdaExpr(ctx *blockCtx, v *ast.LambdaExpr, sig *types.Signature) e
 	for _, v := range v.Rhs {
 		compileExpr(ctx, v)
 	}
-	if rec := ctx.recorder(); rec != nil {
-		rec.Scope(v, ctx.cb.Scope())
-	}
 	ctx.cb.Return(len(v.Rhs)).End(v)
 	return nil
 }
@@ -880,9 +877,6 @@ func compileLambdaExpr2(ctx *blockCtx, v *ast.LambdaExpr2, sig *types.Signature)
 		defNames(ctx, v.Lhs, cb.Scope())
 	}
 	compileStmts(ctx, v.Body.List)
-	if rec := ctx.recorder(); rec != nil {
-		rec.Scope(v, ctx.cb.Scope())
-	}
 	cb.End(v)
 	ctx.cb.SetComments(comments, once)
 	return nil


Test patch:
diff --git a/x/typesutil/info_test.go b/x/typesutil/info_test.go
index 87e083ba..17e59a56 100644
--- a/x/typesutil/info_test.go
+++ b/x/typesutil/info_test.go
@@ -1749,15 +1749,6 @@ func TestScopesInfo(t *testing.T) {
 		{`package p23; func _(){ sum := 0; for x <- [1, 3, 5, 7, 11, 13, 17] { sum = sum + x; c := sum; _ = c } }`, []string{
 			"file:", "func:sum", "for phrase:x", "block:c",
 		}},
-		{`package p23; func test(fn func(int)int){};func _(){test(func(x int) int { y := x*x; return y } ) }`, []string{
-			"file:test", "func:fn", "func:", "func:x y",
-		}},
-		{`package p24; func test(fn func(int)int){};func _(){test( x => x*x );}`, []string{
-			"file:test", "func:fn", "func:", "lambda:x",
-		}},
-		{`package p25; func test(fn func(int)int){};func _(){test( x => { y := x*x; return y } ) }`, []string{
-			"file:test", "func:fn", "func:", "lambda:x y",
-		}},
 	}
 
 	for _, test := range tests {
@@ -1798,10 +1789,6 @@ func TestScopesInfo(t *testing.T) {
 				kind = "range"
 			case *ast.ForPhraseStmt:
 				kind = "for phrase"
-			case *ast.LambdaExpr:
-				kind = "lambda"
-			case *ast.LambdaExpr2:
-				kind = "lambda"
 			default:
 				kind = fmt.Sprintf("<unknown node kind> %T", node)
 			}