S06003

Error Code

S06003

Error Message

Not allowed to define a named function <xxx> within another function. RefId: S06003

Probable Causes

It is not allowed to define a named function within another named function definition. Otherwise, this error will be reported. For example:

def f1() { 
    def f2() { 
        return "Hello" 
    } 
    return f2() 
}

Solutions

  • Change the nested named function to an anonymous function (recommended):
    def f1() {
        f2 = def () { // Define an anonymous function
            return "Hello" 
        } 
        return f2() 
        }
  • Move the nested function to the global scope:

    def f2() { 
        return "Hello" 
    } 
    
    def f1() {
        return f2() 
    }