From 93b3873ae0475c3dc80287955870492c46ddfaeb Mon Sep 17 00:00:00 2001 From: Hackerpilot Date: Sat, 3 Jan 2015 20:44:31 -0800 Subject: [PATCH] Implement #126 --- src/analysis/function_attributes.d | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/src/analysis/function_attributes.d b/src/analysis/function_attributes.d index 3ddcfeb..27a9a0a 100644 --- a/src/analysis/function_attributes.d +++ b/src/analysis/function_attributes.d @@ -48,13 +48,37 @@ class FunctionAttributeCheck : BaseAnalyzer override void visit(const AttributeDeclaration dec) { - if (inInterface > 0 && dec.attribute.attribute == tok!"abstract") + if (inInterface && dec.attribute.attribute == tok!"abstract") { addErrorMessage(dec.attribute.attribute.line, dec.attribute.attribute.column, KEY, ABSTRACT_MESSAGE); } } + override void visit(const FunctionDeclaration dec) + { + if (dec.parameters.parameters.length == 0) + { + bool foundConst = false; + bool foundProperty = false; + foreach (attribute; dec.attributes) + foundConst = foundConst || attribute.attribute.type == tok!"const"; + foreach (attribute; dec.memberFunctionAttributes) + { + foundProperty = foundProperty || (attribute.atAttribute !is null + && attribute.atAttribute.identifier.text == "property"); + foundConst = foundConst || (attribute.tokenType == tok!"const"); + } + if (foundProperty && !foundConst) + { + addErrorMessage(dec.name.line, dec.name.column, KEY, + "Zero-parameter '@property' function should be" + ~ " marked 'const'. "); + } + } + dec.accept(this); + } + override void visit(const Declaration dec) { if (dec.attributes.length == 0)