nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: firecracker-microvm/firecracker-containerd
Pull request #220 (2019-07-10 21:01:34)

runtime: Adding support of setting log levels thru config
Prior to this change the config fields of 'Debug' and 'LogLevel' were
not used and did not set the proper debug level during logging.
- [x] Add tests

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.



Patch:
diff --git a/runtime/service.go b/runtime/service.go
index 2342bed..f851219 100644
--- a/runtime/service.go
+++ b/runtime/service.go
@@ -175,6 +175,11 @@ func NewService(shimCtx context.Context, id string, remotePublisher shim.Publish
 		}
 	}
 
+	if config.Debug {
+		logrus.SetLevel(logrus.DebugLevel)
+		logger.Logger.SetLevel(logrus.DebugLevel)
+	}
+
 	s := &service{
 		taskManager:   vm.NewTaskManager(shimCtx, logger),
 		eventExchange: exchange.NewExchange(),
@@ -582,6 +587,8 @@ func (s *service) buildVMConfiguration(req *proto.CreateVMRequest) (*firecracker
 		LogFifo:      s.shimDir.FirecrackerLogFifoPath(),
 		MetricsFifo:  s.shimDir.FirecrackerMetricsFifoPath(),
 		MachineCfg:   machineConfigurationFromProto(s.config, req.MachineCfg),
+		LogLevel:     s.config.LogLevel,
+		Debug:        s.config.Debug,
 	}
 
 	logger.Debugf("using socket path: %s", cfg.SocketPath)


Test patch:
diff --git a/runtime/service_test.go b/runtime/service_test.go
index 3d83694..ad817d4 100644
--- a/runtime/service_test.go
+++ b/runtime/service_test.go
@@ -15,6 +15,7 @@ package main
 
 import (
 	"context"
+	"fmt"
 	"io/ioutil"
 	"os"
 	"path/filepath"
@@ -198,3 +199,65 @@ func TestBuildVMConfiguration(t *testing.T) {
 		})
 	}
 }
+
+func TestDebugConfig(t *testing.T) {
+	cases := []struct {
+		name    string
+		service *service
+	}{
+		{
+			name: "empty",
+			service: &service{
+				logger: logrus.NewEntry(logrus.New()),
+				config: &Config{},
+			},
+		},
+		{
+			name: "LogLevel set",
+			service: &service{
+				logger: logrus.NewEntry(logrus.New()),
+				config: &Config{
+					LogLevel: "foo",
+				},
+			},
+		},
+		{
+			name: "Debug set",
+			service: &service{
+				logger: logrus.NewEntry(logrus.New()),
+				config: &Config{
+					Debug: true,
+				},
+			},
+		},
+		{
+			name: "Both set",
+			service: &service{
+				logger: logrus.NewEntry(logrus.New()),
+				config: &Config{
+					LogLevel: "foo",
+					Debug:    true,
+				},
+			},
+		},
+	}
+
+	path, err := ioutil.TempDir("./", "TestDebugConfig")
+	assert.NoError(t, err, "failed to create temp directory")
+
+	defer os.RemoveAll(path)
+
+	for i, c := range cases {
+		c := c
+		stubDrivePath := filepath.Join(path, fmt.Sprintf("%d", i))
+		err := os.MkdirAll(stubDrivePath, os.ModePerm)
+		assert.NoError(t, err, "failed to create stub drive path")
+		c.service.stubDriveHandler = newStubDriveHandler(stubDrivePath, c.service.logger)
+		req := proto.CreateVMRequest{}
+
+		cfg, err := c.service.buildVMConfiguration(&req)
+		assert.NoError(t, err, "failed to build firecracker configuration")
+		assert.Equal(t, c.service.config.LogLevel, cfg.LogLevel)
+		assert.Equal(t, c.service.config.Debug, cfg.Debug)
+	}
+}
Repository: firecracker-microvm/firecracker-containerd
Pull request #303 (2019-10-22 23:00:12)

Unit tests shouldn't assume that a certain directory is present
*Issue #, if available:*

NA

*Description of changes:*

This test didn't work on my box and I figured out why...

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.



Patch:
diff --git a/internal/vm/dir.go b/internal/vm/dir.go
index 00fc041..e8c3c7d 100644
--- a/internal/vm/dir.go
+++ b/internal/vm/dir.go
@@ -28,13 +28,13 @@ import (
 	"golang.org/x/sys/unix"
 )
 
-const (
-	varRunDir = "/var/run/firecracker-containerd/"
-)
-
 // ShimDir holds files, sockets and FIFOs scoped to a single shim managing the
 // VM with the given VMID. It is unique per-VM and containerd namespace.
 func ShimDir(namespace, vmID string) (Dir, error) {
+	return shimDir("/var/run/firecracker-containerd/", namespace, vmID)
+}
+
+func shimDir(varRunDir, namespace, vmID string) (Dir, error) {
 	if err := identifiers.Validate(namespace); err != nil {
 		return "", errors.Wrap(err, "invalid namespace")
 	}


Test patch:
diff --git a/internal/vm/dir_test.go b/internal/vm/dir_test.go
index 4672865..dcb165f 100644
--- a/internal/vm/dir_test.go
+++ b/internal/vm/dir_test.go
@@ -14,15 +14,23 @@
 package vm
 
 import (
+	"io/ioutil"
+	"os"
+	"path"
 	"strings"
 	"testing"
 
 	"github.com/stretchr/testify/assert"
+	"github.com/stretchr/testify/require"
 )
 
 var invalidContainerIDs = []string{"", "id?", "*", "id/1", "id\\"}
 
 func TestShimDir(t *testing.T) {
+	runDir, err := ioutil.TempDir("", "run")
+	require.NoError(t, err)
+	defer os.RemoveAll(runDir)
+
 	tests := []struct {
 		name   string
 		ns     string
@@ -40,22 +48,22 @@ func TestShimDir(t *testing.T) {
 		{name: "id with ?", ns: "test", id: "?", outErr: `invalid vm id: identifier "?" must match`},
 		{name: "id with *", ns: "test", id: "*", outErr: `invalid vm id: identifier "*" must match`},
 		{name: "id with ,", ns: "test", id: ",", outErr: `invalid vm id: identifier "," must match`},
-		{name: "valid", ns: "ns", id: "1", outDir: "/run/firecracker-containerd/ns/1"},
-		{name: "valid with dashes", ns: "test-123", id: "123-456", outDir: "/run/firecracker-containerd/test-123/123-456"},
-		{name: "valid with dots", ns: "test.123", id: "123.456", outDir: "/run/firecracker-containerd/test.123/123.456"},
+		{name: "valid", ns: "ns", id: "1", outDir: "ns/1"},
+		{name: "valid with dashes", ns: "test-123", id: "123-456", outDir: "test-123/123-456"},
+		{name: "valid with dots", ns: "test.123", id: "123.456", outDir: "test.123/123.456"},
 	}
 
 	for _, tc := range tests {
 		test := tc
 		t.Run(test.name, func(t *testing.T) {
-			dir, err := ShimDir(test.ns, test.id)
+			dir, err := shimDir(runDir, test.ns, test.id)
 
 			if test.outErr != "" {
 				assert.Error(t, err)
 				assert.True(t, strings.Contains(err.Error(), test.outErr), err.Error())
 			} else {
 				assert.NoError(t, err)
-				assert.EqualValues(t, dir, test.outDir)
+				assert.EqualValues(t, dir, path.Join(runDir, test.outDir))
 			}
 		})
 	}
Repository: goplus/gop
Pull request #1231 (2022-05-31 14:48:13)

v1.1.0


Patch:
diff --git a/VERSION b/VERSION
deleted file mode 100644
index 795460fc..00000000
--- a/VERSION
+++ /dev/null
@@ -1,1 +0,0 @@
-v1.1.0
diff --git a/cl/stmt.go b/cl/stmt.go
index 5f37927d..ce318822 100644
--- a/cl/stmt.go
+++ b/cl/stmt.go
@@ -164,7 +164,18 @@ func compileReturnStmt(ctx *blockCtx, expr *ast.ReturnStmt) {
 					twoValue = (results.Len() == 2)
 				}
 			}
-			compileExpr(ctx, ret, twoValue)
+			switch v := ret.(type) {
+			case *ast.LambdaExpr, *ast.LambdaExpr2:
+				rtyp := ctx.cb.Func().Type().(*types.Signature).Results().At(i).Type()
+				sig, ok := rtyp.(*types.Signature)
+				if !ok {
+					panic(ctx.newCodeErrorf(
+						ret.Pos(), "cannot use lambda expression as type %v in return statement", rtyp))
+				}
+				compileLambda(ctx, v, sig)
+			default:
+				compileExpr(ctx, ret, twoValue)
+			}
 		}
 	}
 	ctx.cb.Return(len(expr.Results), expr)


Test patch:
diff --git a/cl/compile_test.go b/cl/compile_test.go
index ebf1386f..d3cd5040 100644
--- a/cl/compile_test.go
+++ b/cl/compile_test.go
@@ -3225,6 +3225,39 @@ func main() {
 `)
 }
 
+func TestLambdaExpr3(t *testing.T) {
+	gopClTest(t, `
+func intSeq() func() int {
+	i := 0
+	return => {
+		i++
+		return i
+	}
+}
+`, `package main
+
+func intSeq() func() int {
+	i := 0
+	return func() int {
+		i++
+		return i
+	}
+}
+`)
+	gopClTest(t, `
+func intDouble() func(int) int {
+	return i => i*2
+}
+`, `package main
+
+func intDouble() func(int) int {
+	return func(i int) int {
+		return i * 2
+	}
+}
+`)
+}
+
 func TestUnnamedMainFunc(t *testing.T) {
 	gopClTest(t, `i := 1`, `package main
 
diff --git a/cl/error_msg_test.go b/cl/error_msg_test.go
index bdba2d13..68c038c4 100644
--- a/cl/error_msg_test.go
+++ b/cl/error_msg_test.go
@@ -129,6 +129,26 @@ var foo, foo1 func() = nil, => {}
 		"./bar.gop:3:15: lambda unsupport multiple assignment", `
 var foo func()
 _, foo = nil, => {}
+`)
+	codeErrorTest(t,
+		"./bar.gop:4:9: cannot use lambda expression as type int in return statement", `
+func intSeq() int {
+	i := 0
+	return => {
+		i++
+		return i
+	}
+}
+`)
+	codeErrorTest(t,
+		"./bar.gop:6:10: cannot use i (type int) as type string in return argument", `
+func intSeq() func() string {
+	i := 0
+	return => {
+		i++
+		return i
+	}
+}
 `)
 }
Repository: goplus/gop
Pull request #1235 (2022-06-03 16:07:56)

v1.1.0


Patch:
diff --git a/VERSION b/VERSION
deleted file mode 100644
index 795460fc..00000000
--- a/VERSION
+++ /dev/null
@@ -1,1 +0,0 @@
-v1.1.0
diff --git a/cl/compile.go b/cl/compile.go
index b4db8d45..bceb1fc2 100644
--- a/cl/compile.go
+++ b/cl/compile.go
@@ -1059,6 +1059,10 @@ func loadVars(ctx *blockCtx, v *ast.ValueSpec, global bool) {
 					} else {
 						panic(ctx.newCodeErrorf(e.Pos(), "lambda unsupport multiple assignment"))
 					}
+				case *ast.SliceLit:
+					compileSliceLit(ctx, e, typ)
+				case *ast.CompositeLit:
+					compileCompositeLit(ctx, e, typ, false)
 				default:
 					compileExpr(ctx, val)
 				}
diff --git a/cl/expr.go b/cl/expr.go
index 17d8cf22..8e8fed49 100644
--- a/cl/expr.go
+++ b/cl/expr.go
@@ -206,7 +206,7 @@ func compileExpr(ctx *blockCtx, expr ast.Expr, twoValue ...bool) {
 	case *ast.CompositeLit:
 		compileCompositeLit(ctx, v, nil, false)
 	case *ast.SliceLit:
-		compileSliceLit(ctx, v)
+		compileSliceLit(ctx, v, nil)
 	case *ast.RangeExpr:
 		compileRangeExpr(ctx, v)
 	case *ast.IndexExpr:
@@ -776,12 +776,12 @@ func compileCompositeLit(ctx *blockCtx, v *ast.CompositeLit, expected types.Type
 	}
 }
 
-func compileSliceLit(ctx *blockCtx, v *ast.SliceLit) {
+func compileSliceLit(ctx *blockCtx, v *ast.SliceLit, typ types.Type) {
 	n := len(v.Elts)
 	for _, elt := range v.Elts {
 		compileExpr(ctx, elt)
 	}
-	ctx.cb.SliceLit(nil, n)
+	ctx.cb.SliceLit(typ, n)
 }
 
 func compileRangeExpr(ctx *blockCtx, v *ast.RangeExpr) {


Test patch:
diff --git a/cl/compile_test.go b/cl/compile_test.go
index d3cd5040..0d886cdf 100644
--- a/cl/compile_test.go
+++ b/cl/compile_test.go
@@ -1782,6 +1782,22 @@ func foo() *Result {
 `)
 }
 
+func TestCompositeLit5(t *testing.T) {
+	gopClTest(t, `
+type mymap map[float64]string
+var x = {1:"hello", 2:"world"}
+var y map[float64]string = {1:"hello", 2:"world"}
+var z mymap = {1:"hello", 2:"world"}
+`, `package main
+
+type mymap map[float64]string
+
+var x = map[int]string{1: "hello", 2: "world"}
+var y map[float64]string = map[float64]string{1: "hello", 2: "world"}
+var z mymap = mymap{1: "hello", 2: "world"}
+`)
+}
+
 func TestSliceLit(t *testing.T) {
 	gopClTest(t, `
 x := [1, 3.4, 5]
@@ -1795,6 +1811,19 @@ func main() {
 	z := []interface {
 	}{}
 }
+`)
+	gopClTest(t, `
+type vector []float64
+var x = [1, 2, 3]
+var y []float64 = [1, 2, 3]
+var z vector = [1, 2, 3]
+`, `package main
+
+type vector []float64
+
+var x = []int{1, 2, 3}
+var y []float64 = []float64{1, 2, 3}
+var z vector = vector{1, 2, 3}
 `)
 }
Repository: goplus/gop
Pull request #1319 (2022-07-04 12:43:59)

parser: parseBinaryExpr check tuple
```
println (1,2)*2
```
`main.gop:1:9: tuple is not supported`


Patch:
diff --git a/parser/parser.go b/parser/parser.go
index 9754e7af..16d227e3 100644
--- a/parser/parser.go
+++ b/parser/parser.go
@@ -1733,7 +1733,7 @@ func (p *parser) parseLiteralValue(typ ast.Expr) ast.Expr {
 
 // checkExpr checks that x is an expression (and not a type).
 func (p *parser) checkExpr(x ast.Expr) ast.Expr {
-	switch unparen(x).(type) {
+	switch v := unparen(x).(type) {
 	case *ast.BadExpr:
 	case *ast.Ident:
 	case *ast.BasicLit:
@@ -1758,6 +1758,8 @@ func (p *parser) checkExpr(x ast.Expr) ast.Expr {
 	case *ast.ErrWrapExpr:
 	case *ast.LambdaExpr:
 	case *ast.LambdaExpr2:
+	case *tupleExpr:
+		p.error(v.opening, "tuple is not supported")
 	default:
 		// all other nodes are not proper expressions
 		p.errorExpected(x.Pos(), "expression", 3)
@@ -2026,20 +2028,26 @@ func (p *parser) parseBinaryExpr(lhs bool, prec1 int, allowTuple, allowCmd bool)
 		defer un(trace(p, "BinaryExpr"))
 	}
 
-	if x, isTuple = p.parseUnaryExpr(lhs, allowTuple, allowCmd); isTuple {
-		return
-	}
+	x, isTuple = p.parseUnaryExpr(lhs, allowTuple, allowCmd)
 	for {
 		op, oprec := p.tokPrec()
 		if oprec < prec1 {
 			return
 		}
+		if isTuple {
+			p.error(x.(*tupleExpr).opening, "tuple is not supported")
+			return
+		}
 		pos := p.expect(op)
 		if lhs {
 			p.resolve(x)
 			lhs = false
 		}
-		y, _ := p.parseBinaryExpr(false, oprec+1, false, false)
+		y, yIsTuple := p.parseBinaryExpr(false, oprec+1, true, false)
+		if yIsTuple {
+			p.error(y.(*tupleExpr).opening, "tuple is not supported")
+			return
+		}
 		x = &ast.BinaryExpr{X: p.checkExpr(x), OpPos: pos, Op: op, Y: p.checkExpr(y)}
 	}
 }


Test patch:
diff --git a/parser/parser_test.go b/parser/parser_test.go
index 9ece8b55..62be14b5 100644
--- a/parser/parser_test.go
+++ b/parser/parser_test.go
@@ -369,4 +369,10 @@ ast.FuncDecl:
 `)
 }
 
+func TestErrTuple(t *testing.T) {
+	testErrCode(t, `println (1,2)*2`, `/foo/bar.gop:1:9: tuple is not supported`, ``)
+	testErrCode(t, `println 2*(1,2)`, `/foo/bar.gop:1:11: tuple is not supported`, ``)
+	testErrCode(t, `func test() (int,int) { return (100,100)`, `/foo/bar.gop:1:32: tuple is not supported`, ``)
+}
+
 // -----------------------------------------------------------------------------
Repository: goplus/gop
Pull request #1395 (2023-07-12 03:26:07)

parser: check token var


Patch:
diff --git a/parser/parser.go b/parser/parser.go
index 21e206b1..18d0f16b 100644
--- a/parser/parser.go
+++ b/parser/parser.go
@@ -3356,7 +3356,7 @@ func (p *parser) parseValueSpec(doc *ast.CommentGroup, keyword token.Token, iota
 	var typ ast.Expr
 	var tag *ast.BasicLit
 	var values []ast.Expr
-	if p.mode&ParseGoPlusClass != 0 && p.topScope == p.pkgScope && p.varDeclCnt == 1 {
+	if p.mode&ParseGoPlusClass != 0 && p.topScope == p.pkgScope && keyword == token.VAR && p.varDeclCnt == 1 {
 		var starPos token.Pos
 		if p.tok == token.MUL {
 			starPos = p.pos


Test patch:
diff --git a/parser/parser_test.go b/parser/parser_test.go
index 6d2c6aef..a3e8fa1d 100644
--- a/parser/parser_test.go
+++ b/parser/parser_test.go
@@ -419,6 +419,12 @@ func TestClassErrCode(t *testing.T) {
 	v = 10
 )
 `, `/foo/bar.gopx:2:4: syntax error: cannot assign value to field in class file`, ``)
+	testClassErrCode(t, `
+var (
+)
+const c = 100
+const d
+`, `/foo/bar.gopx:5:7: missing constant value`, ``)
 }
 
 // -----------------------------------------------------------------------------
Repository: goplus/gop
Pull request #1398 (2023-07-24 02:35:12)

cl: compileCallExpr check one arg for ast.SliceLit
 https://github.com/goplus/gop/issues/1240 check typetype  must on args.
```
type fvec []float64
fvec([1, 2])
```



Patch:
diff --git a/cl/expr.go b/cl/expr.go
index 5d185db1..2412d6f6 100644
--- a/cl/expr.go
+++ b/cl/expr.go
@@ -520,24 +520,28 @@ func compileCallExpr(ctx *blockCtx, v *ast.CallExpr, inFlags int) {
 			fn.initWith(fnt, i, -1)
 			compileCompositeLit(ctx, expr, fn.arg(i, ellipsis), true)
 		case *ast.SliceLit:
-			fn.initWith(fnt, i, -2)
-			t := fn.arg(i, ellipsis)
-			switch t.(type) {
-			case *types.Slice:
-			case *types.Named:
-				if _, ok := getUnderlying(ctx, t).(*types.Slice); !ok {
+			if len(v.Args) == 1 {
+				fn.initWith(fnt, i, -2)
+				t := fn.arg(i, ellipsis)
+				switch t.(type) {
+				case *types.Slice:
+				case *types.Named:
+					if _, ok := getUnderlying(ctx, t).(*types.Slice); !ok {
+						t = nil
+					}
+				default:
 					t = nil
 				}
-			default:
-				t = nil
-			}
-			typetype := fn.typetype && t != nil && len(v.Args) == 1
-			if typetype {
-				ctx.cb.InternalStack().Pop()
-			}
-			compileSliceLit(ctx, expr, t)
-			if typetype {
-				return
+				typetype := fn.typetype && t != nil
+				if typetype {
+					ctx.cb.InternalStack().Pop()
+				}
+				compileSliceLit(ctx, expr, t)
+				if typetype {
+					return
+				}
+			} else {
+				compileSliceLit(ctx, expr, nil)
 			}
 		default:
 			compileExpr(ctx, arg)
diff --git a/cmd/make.go b/cmd/make.go
index 03fd9b2c..c14554f4 100644
--- a/cmd/make.go
+++ b/cmd/make.go
@@ -452,7 +452,7 @@ func isInChinaWindows() bool {
 		return false
 	}
 	// Check if output contains `zh-cn;`
-	return strings.Contains(out, "zh-cn;")
+	return strings.Contains(out, "zh-cn;") || strings.Contains(out, "zh-hk;")
 }
 
 func isInChina() bool {
@@ -466,7 +466,7 @@ func isInChina() bool {
 	}
 	if strings.HasPrefix(out, prefix) {
 		out = out[len(prefix):]
-		return strings.HasPrefix(out, "zh_CN")
+		return strings.HasPrefix(out, "zh_CN") || strings.HasPrefix(out, "zh_HK")
 	}
 	return false
 }
diff --git a/parser/parser.go b/parser/parser.go
index 18d0f16b..21e206b1 100644
--- a/parser/parser.go
+++ b/parser/parser.go
@@ -3356,7 +3356,7 @@ func (p *parser) parseValueSpec(doc *ast.CommentGroup, keyword token.Token, iota
 	var typ ast.Expr
 	var tag *ast.BasicLit
 	var values []ast.Expr
-	if p.mode&ParseGoPlusClass != 0 && p.topScope == p.pkgScope && keyword == token.VAR && p.varDeclCnt == 1 {
+	if p.mode&ParseGoPlusClass != 0 && p.topScope == p.pkgScope && p.varDeclCnt == 1 {
 		var starPos token.Pos
 		if p.tok == token.MUL {
 			starPos = p.pos


Test patch:
diff --git a/parser/parser_test.go b/parser/parser_test.go
index a3e8fa1d..6d2c6aef 100644
--- a/parser/parser_test.go
+++ b/parser/parser_test.go
@@ -419,12 +419,6 @@ func TestClassErrCode(t *testing.T) {
 	v = 10
 )
 `, `/foo/bar.gopx:2:4: syntax error: cannot assign value to field in class file`, ``)
-	testClassErrCode(t, `
-var (
-)
-const c = 100
-const d
-`, `/foo/bar.gopx:5:7: missing constant value`, ``)
 }
 
 // -----------------------------------------------------------------------------
Repository: goplus/gop
Pull request #1413 (2023-09-20 12:39:33)

parser: fix parseDecl token.FUNC error
fix https://github.com/goplus/gop/issues/1412


Patch:
diff --git a/parser/parser.go b/parser/parser.go
index 2e5a803f..7de73488 100644
--- a/parser/parser.go
+++ b/parser/parser.go
@@ -3636,7 +3636,6 @@ func (p *parser) parseDecl(sync map[token.Token]bool) ast.Decl {
 		decl, call := p.parseFuncDeclOrCall()
 		if decl != nil {
 			if p.errors.Len() != 0 {
-				p.errorExpected(pos, "declaration", 2)
 				p.advance(sync)
 			}
 			return decl


Test patch:
diff --git a/parser/parser_test.go b/parser/parser_test.go
index e1e866d5..1aed0e3f 100644
--- a/parser/parser_test.go
+++ b/parser/parser_test.go
@@ -136,6 +136,20 @@ func h() { var }
 `, `/foo/bar.gop:2:16: expected 'IDENT', found '}' (and 10 more errors)`, ``)
 }
 
+func TestErrInFunc(t *testing.T) {
+	testErrCode(t, `func test() {
+	a,
+}`, `/foo/bar.gop:2:2: expected 1 expression (and 2 more errors)`, ``)
+	testErrCode(t, `func test() {
+	a.test, => {
+	}
+}`, `/foo/bar.gop:2:10: expected operand, found '=>' (and 1 more errors)`, ``)
+	testErrCode(t, `func test() {
+		,
+	}
+}`, `/foo/bar.gop:2:3: expected statement, found ',' (and 1 more errors)`, ``)
+}
+
 // -----------------------------------------------------------------------------
 
 var testStdCode = `package bar; import "io"
Repository: goplus/gop
Pull request #1415 (2023-09-21 11:32:49)

cl: compileIdent class remove clCommandWithoutArgs
fix https://github.com/goplus/gop/issues/1414


Patch:
diff --git a/cl/expr.go b/cl/expr.go
index 5aa4d80b..9b09c8b4 100644
--- a/cl/expr.go
+++ b/cl/expr.go
@@ -98,7 +98,7 @@ func compileIdent(ctx *blockCtx, ident *ast.Ident, flags int) (obj *gox.PkgRef,
 			sig := fn.Ancestor().Type().(*types.Signature)
 			if recv := sig.Recv(); recv != nil {
 				ctx.cb.Val(recv)
-				if compileMember(ctx, ident, name, flags) == nil { // class member object
+				if compileMember(ctx, ident, name, flags&^clCommandWithoutArgs) == nil { // class member object
 					return
 				}
 				ctx.cb.InternalStack().PopN(1)


Test patch:
diff --git a/cl/compile_test.go b/cl/compile_test.go
index 3335a989..8721668f 100644
--- a/cl/compile_test.go
+++ b/cl/compile_test.go
@@ -4515,3 +4515,45 @@ func main() {
 }
 `)
 }
+
+func TestClassFileMember(t *testing.T) {
+	gopClTestFile(t, `type Engine struct {
+}
+
+func (e *Engine) EnterPointerLock() {
+}
+
+func (e *Engine) SetEnable(b bool) {
+}
+
+
+func Engine() *Engine {
+	return &Engine{}
+}
+
+func Test() {
+	engine.setEnable true
+	engine.enterPointerLock
+}
+`, `package main
+
+type Engine struct {
+}
+
+func (e *Engine) EnterPointerLock() {
+}
+func (e *Engine) SetEnable(b bool) {
+}
+
+type Rect struct {
+}
+
+func (this *Rect) Engine() *Engine {
+	return &Engine{}
+}
+func (this *Rect) Test() {
+	this.Engine().SetEnable(true)
+	this.Engine().EnterPointerLock()
+}
+`, "Rect.gox")
+}
Repository: goplus/gop
Pull request #1457 (2023-10-08 08:05:52)

cl: fix compileCallArgs recover check
check compile func internal error.
```
printf("%+v\n", int32)
```


Patch:
diff --git a/cl/expr.go b/cl/expr.go
index 010fa603..cf2f8c1e 100644
--- a/cl/expr.go
+++ b/cl/expr.go
@@ -529,8 +529,13 @@ func compileCallExpr(ctx *blockCtx, v *ast.CallExpr, inFlags int) {
 func compileCallArgs(fn *fnType, fnt types.Type, ctx *blockCtx, v *ast.CallExpr, ellipsis bool, flags gox.InstrFlags) (err error) {
 	n := ctx.cb.InternalStack().Len()
 	defer func() {
-		if v := recover(); v != nil {
-			err = v.(error)
+		if r := recover(); r != nil {
+			if e, ok := r.(error); ok {
+				err = e
+			} else {
+				src, pos := ctx.LoadExpr(v)
+				err = newCodeErrorf(&pos, "compile func %v error: %v", src, r)
+			}
 			ctx.cb.InternalStack().SetLen(n)
 		}
 	}()


Test patch:
diff --git a/cl/error_msg_test.go b/cl/error_msg_test.go
index acda8e11..1bd50aff 100644
--- a/cl/error_msg_test.go
+++ b/cl/error_msg_test.go
@@ -964,3 +964,9 @@ const b = -1
 a := uint128(b)
 `)
 }
+
+func TestErrCompileFunc(t *testing.T) {
+	codeErrorTest(t, `./bar.gop:2:1: compile func printf("%+v\n", int32) error: unreachable`, `
+printf("%+v\n", int32)
+`)
+}
Repository: goplus/gop
Pull request #1494 (2023-10-26 09:51:44)

typesutil.Check fix: exprLHS


Patch:
diff --git a/cl/expr.go b/cl/expr.go
index 83a62447..632308e2 100644
--- a/cl/expr.go
+++ b/cl/expr.go
@@ -355,6 +355,10 @@ func compileSelectorExprLHS(ctx *blockCtx, v *ast.SelectorExpr) {
 		}
 	default:
 		compileExpr(ctx, v.X)
+		if rec := ctx.recorder(); rec != nil {
+			e := ctx.cb.Get(-1)
+			rec.Type(v.X, types.TypeAndValue{Type: e.Type, Value: e.CVal})
+		}
 	}
 	ctx.cb.MemberRef(v.Sel.Name, v)
 }
diff --git a/cl/stmt.go b/cl/stmt.go
index 35847bb4..0bb43cf6 100644
--- a/cl/stmt.go
+++ b/cl/stmt.go
@@ -210,6 +210,7 @@ func compileAssignStmt(ctx *blockCtx, expr *ast.AssignStmt) {
 			if v, ok := lhs.(*ast.Ident); ok {
 				names[i] = v.Name
 			} else {
+				compileExprLHS(ctx, lhs) // only for typesutil.Check
 				log.Panicln("TODO: non-name $v on left side of :=")
 			}
 		}


Test patch:
diff --git a/cl/builtin_test.go b/cl/builtin_test.go
index bc15a433..3f09e167 100644
--- a/cl/builtin_test.go
+++ b/cl/builtin_test.go
@@ -50,6 +50,24 @@ func TestErrMultiStarRecv(t *testing.T) {
 	})
 }
 
+func TestErrAssign(t *testing.T) {
+	defer func() {
+		if e := recover(); e == nil {
+			t.Fatal("TestErrAssign: no panic?")
+		}
+	}()
+	ctx := &blockCtx{}
+	compileAssignStmt(ctx, &ast.AssignStmt{
+		Tok: token.DEFINE,
+		Lhs: []ast.Expr{
+			&ast.SelectorExpr{
+				X:   ast.NewIdent("foo"),
+				Sel: ast.NewIdent("bar"),
+			},
+		},
+	})
+}
+
 func TestErrPanicToRecv(t *testing.T) {
 	ctx := &blockCtx{
 		tlookup: &typeParamLookup{