protected override void VisitCastDefinitionSyntax(CastDefinitionSyntax pNode) { using (var rf = Store.AddValue("ReturnFound", false)) { using (var rvc = Store.AddValue("ReturnValueCount", pNode.ReturnValues.Count)) { base.VisitCastDefinitionSyntax(pNode); if (pNode.ReturnValues.Count != 0 && !rf.Value) { CompilerErrors.MethodReturnPaths(pNode, pNode.Span); } else if (pNode.ReturnValues.Count == 0 && rf.Value) { CompilerErrors.MethodNoReturn(pNode, pNode.Span); } } } }
protected override void VisitMethodSyntax(MethodSyntax pNode) { if (pNode.External) { KeyAnnotations.ValidateExternalAnnotation(pNode.Annotation, pNode); } //Validate that one and only 1 method is annotated with "run" //This method must contain no parameters and return no values if (pNode.Annotation.Value == KeyAnnotations.RunMethod) { if (Store.GetValue <string>("RunMethod") != null) { CompilerErrors.RunMethodDuplicate(Store.GetValue <string>("RunMethod"), pNode.Name, pNode.Span); return; } Store.SetValue("RunMethod", pNode.Name); if (pNode.Parameters.Count != 0) { CompilerErrors.RunMethodParameters(pNode.Span); } if (pNode.ReturnValues.Count != 0) { CompilerErrors.RunMethodReturn(pNode.Span); } } using (var ic = Store.AddValue("InConstructor", pNode.Annotation.Value == KeyAnnotations.Constructor)) { using (var rf = Store.AddValue("ReturnFound", false)) { using (var rvc = Store.AddValue("ReturnValueCount", pNode.ReturnValues.Count)) { _usedFields = new HashSet <string>(); base.VisitMethodSyntax(pNode); //Validate that all paths return a value if (pNode.Body != null) { if (pNode.ReturnValues.Count != 0 && !rf.Value) { CompilerErrors.MethodReturnPaths(pNode, pNode.Span); } else if (pNode.ReturnValues.Count == 0 && rf.Value) { CompilerErrors.MethodNoReturn(pNode, pNode.Span); } } } } if (ic.Value) { SmallType s = Struct; if (s != null) { foreach (var f in s.GetFields()) { if (!_usedFields.Contains(f.Name)) { CompilerErrors.FieldNotInitialized(f.Name, pNode.Span); } } } } } }