Skip to content

Commit 746814e

Browse files
authored
Merge pull request #1175 from anatoly32322/fix-function-id
Add go with anonymous function case in gstack
2 parents 72000e0 + 00c8d7e commit 746814e

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
* Added `Struct` support for `Variant` in `ydb.ParamsBuilder()`
2+
* Added `go` with anonymous function case in `gstack`
23

34
## v3.61.2
45
* Changed default transaction control to `NoTx` for execute query through query service client

internal/cmd/gstack/main.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,12 @@ func getCallExpressionsFromStmt(statement ast.Stmt) (listOfCallExpressions []*as
7979
body = stmt.Body
8080
case *ast.ForStmt:
8181
body = stmt.Body
82+
case *ast.GoStmt:
83+
if fun, ok := stmt.Call.Fun.(*ast.FuncLit); ok {
84+
listOfCallExpressions = append(listOfCallExpressions, getListOfCallExpressionsFromBlockStmt(fun.Body)...)
85+
} else {
86+
listOfCallExpressions = append(listOfCallExpressions, stmt.Call)
87+
}
8288
case *ast.RangeStmt:
8389
body = stmt.Body
8490
case *ast.DeclStmt:

internal/stack/function_id_test.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
package stack
22

33
import (
4+
"sync"
45
"testing"
6+
"time"
57

68
"github.com/stretchr/testify/require"
79
)
@@ -22,6 +24,22 @@ func (e *starType) starredCall() string {
2224
return FunctionID("").FunctionID()
2325
}
2426

27+
func anonymousFunctionCall() string {
28+
var result string
29+
var mu sync.Mutex
30+
go func() {
31+
mu.Lock()
32+
defer mu.Unlock()
33+
result = FunctionID("").FunctionID()
34+
}()
35+
time.Sleep(time.Second)
36+
37+
mu.Lock()
38+
defer mu.Unlock()
39+
40+
return result
41+
}
42+
2543
func TestFunctionIDForGenericType(t *testing.T) {
2644
t.Run("StaticFunc", func(t *testing.T) {
2745
require.Equal(t,
@@ -42,4 +60,10 @@ func TestFunctionIDForGenericType(t *testing.T) {
4260
x.starredCall(),
4361
)
4462
})
63+
t.Run("AnonymousFunctionCall", func(t *testing.T) {
64+
require.Equal(t,
65+
"github.com/ydb-platform/ydb-go-sdk/v3/internal/stack.anonymousFunctionCall",
66+
anonymousFunctionCall(),
67+
)
68+
})
4569
}

0 commit comments

Comments
 (0)