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)
| 248 | // Adds a function decl if one doesn't already exist, then adds all overloads from the Decl. |
| 249 | // If overload overlaps with an existing overload, adds to the errors in the Env instead. |
| 250 | func (e *Env) setFunction(fn *decls.FunctionDecl) []errorMsg { |
| 251 | errMsgs := make([]errorMsg, 0) |
| 252 | current := e.declarations.FindFunction(fn.Name()) |
| 253 | if current != nil { |
| 254 | var err error |
| 255 | current, err = current.Merge(fn) |
| 256 | if err != nil { |
| 257 | return append(errMsgs, errorMsg(err.Error())) |
| 258 | } |
| 259 | } else { |
| 260 | current = fn |
| 261 | } |
| 262 | for _, overload := range current.OverloadDecls() { |
| 263 | for _, macro := range parser.AllMacros { |
| 264 | if macro.Function() == current.Name() && |
| 265 | macro.IsReceiverStyle() == overload.IsMemberFunction() && |
| 266 | macro.ArgCount() == len(overload.ArgTypes()) { |
| 267 | errMsgs = append(errMsgs, overlappingMacroError(current.Name(), macro.ArgCount())) |
| 268 | } |
| 269 | } |
| 270 | if len(errMsgs) > 0 { |
| 271 | return errMsgs |
| 272 | } |
| 273 | } |
| 274 | e.declarations.SetFunction(current) |
| 275 | return errMsgs |
| 276 | } |
| 277 | |
| 278 | func maybeMergeConstant(a *decls.VariableDecl, b *decls.VariableDecl) (*decls.VariableDecl, errorMsg) { |
| 279 | if b.Value() != nil { |
no test coverage detected