@@ -2,10 +2,10 @@ package eval
2
2
3
3
import (
4
4
"fmt"
5
- "path/filepath"
6
5
"reflect"
7
6
"runtime"
8
7
"strings"
8
+ "unicode"
9
9
)
10
10
11
11
// RunDSL iterates through the root expressions and calls WalkSets on each to
@@ -116,8 +116,7 @@ func ReportError(fm string, vals ...any) {
116
116
// IncompatibleDSL should be called by DSL functions when they are invoked in an
117
117
// incorrect context (e.g. "Params" in "Service").
118
118
func IncompatibleDSL () {
119
- elems := strings .Split (caller (), "." )
120
- ReportError ("invalid use of %s" , elems [len (elems )- 1 ])
119
+ ReportError ("invalid use of %s" , caller ())
121
120
}
122
121
123
122
// InvalidArgError records an invalid argument error. It is used by DSL
@@ -235,13 +234,20 @@ func finalizeSet(set ExpressionSet) {
235
234
236
235
// caller returns the name of calling function.
237
236
func caller () string {
238
- pc , file , _ , ok := runtime .Caller (2 )
239
- if ok && filepath .Base (file ) == "current.go" {
240
- pc , _ , _ , ok = runtime .Caller (3 )
241
- }
242
- if ! ok {
243
- return "<unknown>"
237
+ for skip := 2 ; skip <= 3 ; skip ++ {
238
+ pc , _ , _ , ok := runtime .Caller (skip )
239
+ if ! ok {
240
+ break
241
+ }
242
+ name := runtime .FuncForPC (pc ).Name ()
243
+ elems := strings .Split (name , "." )
244
+ caller := elems [len (elems )- 1 ]
245
+ for _ , first := range caller {
246
+ if unicode .IsUpper (first ) {
247
+ return caller
248
+ }
249
+ break
250
+ }
244
251
}
245
-
246
- return runtime .FuncForPC (pc ).Name ()
252
+ return "<unknown>"
247
253
}
0 commit comments