(final QueryContext qc, final InputInfo ii)
| 330 | } |
| 331 | |
| 332 | @Override |
| 333 | public FuncItem item(final QueryContext qc, final InputInfo ii) throws QueryException { |
| 334 | final Expr body; |
| 335 | if(global.isEmpty()) { |
| 336 | body = expr; |
| 337 | } else { |
| 338 | // collect closure |
| 339 | final LinkedList<Clause> clauses = new LinkedList<>(); |
| 340 | for(final Entry<Var, Expr> entry : global.entrySet()) { |
| 341 | clauses.add(new Let(entry.getKey(), entry.getValue().value(qc))); |
| 342 | } |
| 343 | body = new GFLWOR(info, clauses, expr); |
| 344 | } |
| 345 | |
| 346 | final SeqType argType = body.seqType(); |
| 347 | final Expr checked; |
| 348 | if(declType == null || argType.instanceOf(declType)) { |
| 349 | // return type is already correct |
| 350 | checked = body; |
| 351 | } else if(body instanceof final Value value) { |
| 352 | // we can type check immediately |
| 353 | checked = declType.coerce(value, qc, info, name, null); |
| 354 | } else { |
| 355 | // check at each call: reject impossible arities |
| 356 | if(argType.type.instanceOf(declType.type) && argType.occ.intersect(declType.occ) == null && |
| 357 | !body.has(Flag.NDT)) { |
| 358 | throw typeError(body, declType, name, info); |
| 359 | } |
| 360 | checked = new TypeCheck(info, body, declType); |
| 361 | } |
| 362 | |
| 363 | final FuncType ft = (FuncType) seqType().type; |
| 364 | return new FuncItem(info, checked, params, anns, ft, vs.stackSize(), name); |
| 365 | } |
| 366 | |
| 367 | @Override |
| 368 | public boolean has(final Flag... flags) { |
nothing calls this directly
no test coverage detected