nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: goplus/gop
Pull request #2033 (2024-12-08 22:42:04)

mini spec: Short variable declarations


Patch:
diff --git a/doc/spec-mini.md b/doc/spec-mini.md
index e93a213f..385b53fd 100644
--- a/doc/spec-mini.md
+++ b/doc/spec-mini.md
@@ -1991,9 +1991,15 @@ var n = nil            // illegal
 
 Implementation restriction: A compiler may make it illegal to declare a variable inside a [function body](#function-declarations) if the variable is never used.
 
-### Short variable declarations
+In a function body, variables do not need to be explicitly defined.
 
-TODO
+```go
+d := math.Sin(0.5)  // d is float64
+i := 42             // i is int
+t, ok := x.(T)      // t is T, ok is bool
+```
+
+See [short variable declarations](#short-variable-declarations).
 
 ### Function declarations
 
diff --git a/go.mod b/go.mod
index 10b3a11e..cbe3b4a8 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.4-0.20241205134824-ac870e207d8f
+	github.com/goplus/gogen v1.16.3
 	github.com/goplus/llgo v0.9.8
 	github.com/goplus/mod v0.13.12
 	github.com/qiniu/x v1.13.10
diff --git a/go.sum b/go.sum
index cead13c2..e1e847ac 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.4-0.20241205134824-ac870e207d8f h1:+CwzStluc1MGjEQbR5CQOXWOqlBLYnaeECKcSXrHYKg=
-github.com/goplus/gogen v1.16.4-0.20241205134824-ac870e207d8f/go.mod h1:6TQYbabXDF9LCdDkOOzHmfg1R4ENfXQ3XpHa9RhTSD8=
+github.com/goplus/gogen v1.16.3 h1:nNkV1b6zd89d/UhMb4bZHcEfdAHtPaadrJFXNcoUITI=
+github.com/goplus/gogen v1.16.3/go.mod h1:6TQYbabXDF9LCdDkOOzHmfg1R4ENfXQ3XpHa9RhTSD8=
 github.com/goplus/llgo v0.9.8 h1:9qFO5sEYzTXYixNL9m9qDNfI2kjtnU3bPMf5hOwQlME=
 github.com/goplus/llgo v0.9.8/go.mod h1:1phqPJEgr/uw59PRz/NB7s54OoP+NGjC6pz0HovT5JY=
 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 90bbdd66..04742bf2 100644
--- a/cl/compile_gop_test.go
+++ b/cl/compile_gop_test.go
@@ -1630,37 +1630,3 @@ func main() {
 }
 `)
 }
-
-func TestOverloadUntyped(t *testing.T) {
-	gopMixedClTest(t, "main", `
-package main
-
-type specialObj int
-type SpriteName string
-
-type SpriteImpl struct {
-}
-
-func (p *SpriteImpl) turn(v any) {
-}
-func (p *SpriteImpl) TurnTo__0(sprite *SpriteImpl) {
-}
-func (p *SpriteImpl) TurnTo__1(sprite SpriteName) {
-}
-func (p *SpriteImpl) TurnTo__2(obj specialObj) {
-}
-func (p *SpriteImpl) TurnTo__3(degree float64) {
-}
-`, `
-p := &SpriteImpl{}
-p.turnTo 180.0
-p.turnTo 180.1
-`, `package main
-
-func main() {
-	p := &SpriteImpl{}
-	p.TurnTo__2(180.0)
-	p.TurnTo__3(180.1)
-}
-`)
-}
Repository: goplus/gop
Pull request #2108 (2025-02-15 16:56:43)

compileSendStmt: support slice append (#2107)
#2107


Patch:
diff --git a/cl/stmt.go b/cl/stmt.go
index 57c4cefa..b2d4ff12 100644
--- a/cl/stmt.go
+++ b/cl/stmt.go
@@ -243,9 +243,44 @@ func compileIncDecStmt(ctx *blockCtx, expr *ast.IncDecStmt) {
 	ctx.cb.IncDec(gotoken.Token(expr.Tok))
 }
 
+// issue #2107:
+//
+//	a <- v
+//	foo.a <- v
+func isAppendable(x ast.Expr) bool {
+	switch x := x.(type) {
+	case *ast.Ident:
+		return true
+	case *ast.SelectorExpr:
+		_, ok := x.X.(*ast.Ident)
+		return ok
+	}
+	return false
+}
+
 func compileSendStmt(ctx *blockCtx, expr *ast.SendStmt) {
-	compileExpr(ctx, expr.Chan)
-	compileExpr(ctx, expr.Value)
+	cb := ctx.cb
+	ch, v := expr.Chan, expr.Value
+	stk := cb.InternalStack()
+	if isAppendable(ch) { // a <- v (issue #2107)
+		compileExpr(ctx, ch)
+		a := stk.Get(-1)
+		t := a.Type.Underlying()
+		if _, ok := t.(*types.Slice); ok { // a = append(a, x)
+			stk.Pop()
+			compileExprLHS(ctx, ch)
+			cb.Val(ctx.pkg.Builtin().Ref("append"))
+			stk.Push(a)
+			compileExpr(ctx, v)
+			cb.CallWith(2, 0, expr).AssignWith(1, 1, expr)
+			return
+		}
+		goto normal
+	}
+	compileExpr(ctx, ch)
+
+normal:
+	compileExpr(ctx, v)
 	ctx.cb.Send()
 }
 


Test patch:
diff --git a/cl/_testgop/append/in.gop b/cl/_testgop/append/in.gop
new file mode 100644
index 00000000..5956a8ab
--- /dev/null
+++ b/cl/_testgop/append/in.gop
@@ -0,0 +1,14 @@
+type foo struct {
+	a []int
+}
+
+a := [1, 2, 3]
+a <- 4
+echo a
+
+f := foo{a: [1, 2, 3]}
+f.a <- 4
+echo f
+
+f2 := [2]chan int{}
+f2[0] <- 4
diff --git a/cl/_testgop/append/out.go b/cl/_testgop/append/out.go
new file mode 100644
index 00000000..e0dcabed
--- /dev/null
+++ b/cl/_testgop/append/out.go
@@ -0,0 +1,18 @@
+package main
+
+import "fmt"
+
+type foo struct {
+	a []int
+}
+
+func main() {
+	a := []int{1, 2, 3}
+	a = append(a, 4)
+	fmt.Println(a)
+	f := foo{a: []int{1, 2, 3}}
+	f.a = append(f.a, 4)
+	fmt.Println(f)
+	f2 := [2]chan int{}
+	f2[0] <- 4
+}