Skip to content

Commit b270eba

Browse files
authored
Merge pull request #5948 from MDoerner/FixDecOnConstAgain
Fix missing part for VarDesc on constants
2 parents 7c523c4 + 47c62f7 commit b270eba

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

Rubberduck.Parsing/VBA/Parsing/AttributeListener.cs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ public override void EnterStartRule(VBAParser.StartRuleContext context)
3434

3535
public override void EnterModuleVariableStmt(VBAParser.ModuleVariableStmtContext context)
3636
{
37-
var variableDeclarationStatemenList = context.variableStmt().variableListStmt().variableSubStmt();
38-
foreach (var variableContext in variableDeclarationStatemenList)
37+
var variableDeclarationStatementList = context.variableStmt().variableListStmt().variableSubStmt();
38+
foreach (var variableContext in variableDeclarationStatementList)
3939
{
4040
var variableName = Identifier.GetName(variableContext);
4141
_membersAllowingAttributes[(variableName, DeclarationType.Variable)] = context;
@@ -169,19 +169,29 @@ public override void ExitAttributeStmt(VBAParser.AttributeStmtContext context)
169169

170170
var scopeName = attributeNameParts[0];
171171

172-
//Might be an attribute for the enclosing procedure, function or poperty.
172+
//Might be an attribute for the enclosing procedure, function or property.
173173
if (_currentScopeAttributes != null && scopeName.Equals(_currentScope.scopeIdentifier, StringComparison.OrdinalIgnoreCase))
174174
{
175175
AddOrUpdateAttribute(_currentScopeAttributes, attributeName, context);
176176
return;
177177
}
178178

179+
//Member attributes
180+
//Due to the VBA naming rules, a name can only refer to either a variable or constant.
181+
179182
//Member variable attributes
180183
var moduleVariableScope = (scopeName, DeclarationType.Variable);
181184
if (_membersAllowingAttributes.TryGetValue(moduleVariableScope, out _))
182185
{
183186
AddOrUpdateAttribute(moduleVariableScope, attributeName, context);
184187
}
188+
189+
//Member constant attributes
190+
var moduleConstantScope = (scopeName, DeclarationType.Constant);
191+
if (_membersAllowingAttributes.TryGetValue(moduleConstantScope, out _))
192+
{
193+
AddOrUpdateAttribute(moduleConstantScope, attributeName, context);
194+
}
185195
}
186196

187197
private void AddOrUpdateAttribute((string scopeName, DeclarationType Variable) moduleVariableScope,

RubberduckTests/Inspections/MissingAttributeInspectionTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ public void VariableDescriptionAnnotationWithoutAttributeReturnsResult_Constant(
327327

328328
[Test]
329329
[Category("Inspections")]
330-
public void Variable_DescriptionAnnotationWithAttributeReturnsResult_Constant()
330+
public void Variable_DescriptionAnnotationWithAttributeReturnsNoResult_Constant()
331331
{
332332
const string inputCode =
333333
@"'@VariableDescription ""Desc""
@@ -336,7 +336,7 @@ public void Variable_DescriptionAnnotationWithAttributeReturnsResult_Constant()
336336
";
337337

338338
var inspectionResults = InspectionResults(inputCode);
339-
Assert.AreEqual(1, inspectionResults.Count());
339+
Assert.IsFalse(inspectionResults.Any());
340340
}
341341

342342
[Test]
@@ -481,4 +481,4 @@ protected override IInspection InspectionUnderTest(RubberduckParserState state)
481481
return new MissingAttributeInspection(state);
482482
}
483483
}
484-
}
484+
}

0 commit comments

Comments
 (0)