(rootNode *RootAssertionNode, node *ast.ReturnStmt, expr ast.Expr, retKey *annotation.RetAnnotationKey, isNamedReturn bool)
| 853 | } |
| 854 | |
| 855 | func addReturnConsumers(rootNode *RootAssertionNode, node *ast.ReturnStmt, expr ast.Expr, retKey *annotation.RetAnnotationKey, isNamedReturn bool) { |
| 856 | // add shallow consumer |
| 857 | rootNode.AddConsumption(&annotation.ConsumeTrigger{ |
| 858 | Annotation: &annotation.UseAsReturn{ |
| 859 | TriggerIfNonNil: &annotation.TriggerIfNonNil{ |
| 860 | Ann: retKey}, |
| 861 | IsNamedReturn: isNamedReturn, |
| 862 | RetStmt: node}, |
| 863 | Expr: expr, |
| 864 | Guards: guard.NoGuards(), |
| 865 | }) |
| 866 | |
| 867 | // If expr is a deep type, then we track its deep nilability as well. |
| 868 | // ``` |
| 869 | // E.g., func foo(s []*int) []*int { |
| 870 | // s[0] = nil |
| 871 | // return s // <-- track shallow and deep nilability of `s` here |
| 872 | // } |
| 873 | // ``` |
| 874 | if typeshelper.IsDeep(rootNode.Pass().TypesInfo.TypeOf(expr)) { |
| 875 | producer := &annotation.ProduceTrigger{ |
| 876 | Annotation: exprAsDeepProducer(rootNode, expr), |
| 877 | Expr: expr, |
| 878 | } |
| 879 | consumer := &annotation.ConsumeTrigger{ |
| 880 | Annotation: &annotation.UseAsReturnDeep{ |
| 881 | TriggerIfDeepNonNil: &annotation.TriggerIfDeepNonNil{ |
| 882 | Ann: retKey}, |
| 883 | IsNamedReturn: isNamedReturn, |
| 884 | RetStmt: node}, |
| 885 | Expr: expr, |
| 886 | Guards: guard.NoGuards(), |
| 887 | } |
| 888 | // since this is an implicit tracking of the deep nilability of expr, we don't need to |
| 889 | // check for its guarding. |
| 890 | consumer.Annotation.SetNeedsGuard(false) |
| 891 | |
| 892 | // We add a full trigger here directly because if we add only a deep consumer here, then it gets added |
| 893 | // to the same assertion node in the assertion tree as for the shallow consumer above. This is a problem |
| 894 | // since a producer actually meant for the shallow consumer also incorrectly matches the deep consumer. |
| 895 | rootNode.AddNewTriggers(annotation.FullTrigger{ |
| 896 | Producer: producer, |
| 897 | Consumer: consumer, |
| 898 | }) |
| 899 | } |
| 900 | } |
no test coverage detected