(final CompileContext cc)
| 32 | } |
| 33 | |
| 34 | @Override |
| 35 | protected Expr opt(final CompileContext cc) throws QueryException { |
| 36 | final Expr func = arg(0), args = arg(1); |
| 37 | FuncType ft = func.funcType(); |
| 38 | final Type argsTp = args.seqType().type; |
| 39 | |
| 40 | // try to pass on types of array argument to function item |
| 41 | if(argsTp instanceof final ArrayType aat) { |
| 42 | if(args instanceof final XQArray array) { |
| 43 | // argument is a value: final types are known |
| 44 | final int as = Math.max(0, (int) array.structSize()); |
| 45 | final SeqType[] ast = new SeqType[as]; |
| 46 | for(int a = 0; a < as; a++) ast[a] = array.valueAt(a).seqType(); |
| 47 | arg(0, arg -> refineFunc(arg, cc, ast)); |
| 48 | } else if(ft != null) { |
| 49 | // argument will be of type array: assign generic array return type to all arguments |
| 50 | final SeqType[] at = ft.argTypes; |
| 51 | if(at != null) { |
| 52 | final SeqType[] ast = new SeqType[at.length]; |
| 53 | Arrays.fill(ast, aat.valueType()); |
| 54 | arg(0, arg -> refineFunc(arg, cc, ast)); |
| 55 | } |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | ft = arg(0).funcType(); |
| 60 | if(ft != null) exprType.assign(ft.declType); |
| 61 | return this; |
| 62 | } |
| 63 | |
| 64 | /** |
| 65 | * Applies a function with the specified arguments. |
nothing calls this directly
no test coverage detected