(n ast.Node, id string, args []sem.Expr, argTypes []super.Type)
| 72 | } |
| 73 | |
| 74 | func (r *resolver) mustResolveCall(n ast.Node, id string, args []sem.Expr, argTypes []super.Type) (sem.Expr, super.Type) { |
| 75 | d, ok := r.decls[id] |
| 76 | if !ok { |
| 77 | panic(id) |
| 78 | } |
| 79 | // Translate the decl ID to a func by converting any |
| 80 | // function refs passed as args to a key into the variants table removing |
| 81 | // correponding args. |
| 82 | var params []string |
| 83 | var exprs []sem.Expr |
| 84 | declParams := d.lambda.Params |
| 85 | if len(declParams) != len(args) { |
| 86 | r.t.error(n, fmt.Errorf("%q: expected %d params but called with %d", d.name, len(declParams), len(args))) |
| 87 | return badExpr, r.t.checker.unknown |
| 88 | } |
| 89 | var lambdas []lambda |
| 90 | var fields []super.Field |
| 91 | for k, arg := range args { |
| 92 | if f, ok := arg.(*sem.FuncRef); ok { |
| 93 | lambdas = append(lambdas, lambda{param: declParams[k].Name, pos: k, id: f.ID}) |
| 94 | continue |
| 95 | } |
| 96 | params = append(params, declParams[k].Name) |
| 97 | exprs = append(exprs, arg) |
| 98 | fields = append(fields, super.NewField(declParams[k].Name, argTypes[k])) |
| 99 | } |
| 100 | argType := r.t.sctx.MustLookupTypeRecord(fields) |
| 101 | if len(declParams) == len(params) { |
| 102 | // No need to specialize this call since no function args are being passed. |
| 103 | tag, typ := r.lookupFixed(id, argType) |
| 104 | return &sem.CallExpr{ |
| 105 | Node: n, |
| 106 | Tag: tag, |
| 107 | Args: args, |
| 108 | }, typ |
| 109 | } |
| 110 | // Enter the new function scope and set up the bindings for the |
| 111 | // values we retrieved above while evaluating args in the outer scope. |
| 112 | return &sem.CallExpr{ |
| 113 | Node: n, |
| 114 | Tag: r.getVariant(id, params, lambdas, argType).tag, |
| 115 | Args: exprs, |
| 116 | }, r.t.checker.unknown |
| 117 | } |
| 118 | |
| 119 | func (r *resolver) resolveVariant(d *funcDecl, variant *funcDef, inType super.Type) { |
| 120 | save := r.t.scope |
no test coverage detected