@@ -94,7 +94,7 @@ func replaceIdent(root syntax.Node, match string, to string) {
94
94
})
95
95
}
96
96
97
- func rewriteStdAndGenericFuncs (funcDecls []* DeclInfo , pkgPath string ) {
97
+ func rewriteFuncsSource (funcDecls []* DeclInfo , pkgPath string ) {
98
98
for _ , fn := range funcDecls {
99
99
if ! fn .Kind .IsFunc () {
100
100
continue
@@ -119,6 +119,13 @@ func rewriteStdAndGenericFuncs(funcDecls []*DeclInfo, pkgPath string) {
119
119
fnDecl := fn .FuncDecl
120
120
pos := fn .FuncDecl .Pos ()
121
121
122
+ // check if body contains recover(), if so
123
+ // do not add interceptor
124
+ // see https://github.com/xhd2015/xgo/issues/164
125
+ if hasRecoverCall (fnDecl .Body ) {
126
+ continue
127
+ }
128
+
122
129
fnName := fnDecl .Name .Value
123
130
124
131
// dump
@@ -136,6 +143,7 @@ func rewriteStdAndGenericFuncs(funcDecls []*DeclInfo, pkgPath string) {
136
143
// cannot trap
137
144
continue
138
145
}
146
+
139
147
// stop if __xgo_link_generated_trap conflict with recv?
140
148
preset [XgoLinkTrapForGenerated ] = true
141
149
@@ -414,6 +422,23 @@ func getPresetNames(node syntax.Node) map[string]bool {
414
422
return preset
415
423
}
416
424
425
+ func hasRecoverCall (node syntax.Node ) bool {
426
+ var found bool
427
+ syntax .Inspect (node , func (n syntax.Node ) bool {
428
+ if n == nil {
429
+ return false
430
+ }
431
+ if call , ok := n .(* syntax.CallExpr ); ok {
432
+ if idt , ok := call .Fun .(* syntax.Name ); ok && idt .Value == "recover" {
433
+ found = true
434
+ return false
435
+ }
436
+ }
437
+ return true
438
+ })
439
+ return found
440
+ }
441
+
417
442
func copyFuncDeclWithoutBody (decl * syntax.FuncDecl ) * syntax.FuncDecl {
418
443
return copyFuncDecl (decl , false )
419
444
}
0 commit comments