setFunction adds the function Decl to the Env. Adds a function decl if one doesn't already exist, then adds all overloads from the Decl. If overload overlaps with an existing overload, adds to the errors in the Env instead.
(fn *decls.FunctionDecl)
| 267 | // Adds a function decl if one doesn't already exist, then adds all overloads from the Decl. |
| 268 | // If overload overlaps with an existing overload, adds to the errors in the Env instead. |
| 269 | func (e *Env) setFunction(fn *decls.FunctionDecl) []errorMsg { |
| 270 | errMsgs := make([]errorMsg, 0) |
| 271 | current := e.declarations.FindFunction(fn.Name()) |
| 272 | if current != nil { |
| 273 | var err error |
| 274 | current, err = current.Merge(fn) |
| 275 | if err != nil { |
| 276 | return append(errMsgs, errorMsg(err.Error())) |
| 277 | } |
| 278 | } else { |
| 279 | current = fn |
| 280 | } |
| 281 | for _, overload := range current.OverloadDecls() { |
| 282 | for _, macro := range parser.AllMacros { |
| 283 | if macro.Function() == current.Name() && |
| 284 | macro.IsReceiverStyle() == overload.IsMemberFunction() && |
| 285 | macro.ArgCount() == len(overload.ArgTypes()) { |
| 286 | errMsgs = append(errMsgs, overlappingMacroError(current.Name(), macro.ArgCount())) |
| 287 | } |
| 288 | } |
| 289 | if len(errMsgs) > 0 { |
| 290 | return errMsgs |
| 291 | } |
| 292 | } |
| 293 | e.declarations.SetFunction(current) |
| 294 | return errMsgs |
| 295 | } |
| 296 | |
| 297 | func maybeMergeConstant(a *decls.VariableDecl, b *decls.VariableDecl) (*decls.VariableDecl, errorMsg) { |
| 298 | if b.Value() != nil { |
no test coverage detected