Skip to content

Commit 6d6a2d3

Browse files
committed
fixed default member logic
1 parent 578792d commit 6d6a2d3

File tree

2 files changed

+8
-15
lines changed

2 files changed

+8
-15
lines changed

Rubberduck.Inspections/VariableRequiresSetAssignmentEvaluator.cs

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -74,17 +74,9 @@ public static bool RequiresSetAssignment(IdentifierReference reference, Rubberdu
7474

7575
if (isObjectVariable)
7676
{
77-
// get the members of the returning type, a default member could make us lie otherwise
7877
var classModule = declaration.AsTypeDeclaration as ClassModuleDeclaration;
79-
if (HasParameterlessDefaultMember(classModule))
80-
{
81-
// assigned declaration has a default parameterless member, which is legally being assigned here.
82-
// might be a good idea to flag that default member assignment though...
83-
return false;
84-
}
85-
86-
// assign declaration is an object without a default parameterless (or with all parameters optional) member - LHS needs a 'Set' keyword.
87-
return true;
78+
// if assigned declaration is an object without a default parameterless (or with all parameters optional) member, LHS needs a 'Set' keyword.
79+
return !HasParameterlessDefaultMember(classModule);
8880
}
8981

9082
// assigned declaration is a variant. we need to know about the RHS of the assignment.
@@ -115,7 +107,7 @@ public static bool RequiresSetAssignment(IdentifierReference reference, Rubberdu
115107
if (lastRef?.Declaration.IsObject ?? false)
116108
{
117109
// the last reference in the expression is referring to an object type
118-
// return true *if* the object doesn't have a default member
110+
// return true *if* the object doesn't have a parameterless default member
119111
var typeDeclaration = lastRef.Declaration.AsTypeDeclaration as ClassModuleDeclaration;
120112
return !HasParameterlessDefaultMember(typeDeclaration);
121113
}

Rubberduck.Parsing/ComReflection/ReferencedDeclarationsCollector.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ public List<Declaration> LoadDeclarationsFromLibrary()
142142
{
143143
var moduleName = new QualifiedModuleName(_referenceName, _path,
144144
module.Type == DeclarationType.Enumeration || module.Type == DeclarationType.UserDefinedType
145-
? string.Format("_{0}", module.Name)
145+
? $"_{module.Name}"
146146
: module.Name);
147147

148148
var declaration = CreateModuleDeclaration(module, moduleName, project, GetModuleAttributes(module));
@@ -235,8 +235,9 @@ private void CreateMemberDeclarations(IEnumerable<ComMember> members, QualifiedM
235235
_declarations.AddRange(hasParams.Parameters);
236236
memberTree.AddChildren(hasParams.Parameters);
237237
}
238-
var coClass = memberDeclaration as ClassModuleDeclaration;
239-
if (coClass != null && item == defaultMember)
238+
239+
var coClass = declaration as ClassModuleDeclaration;
240+
if (coClass != null && item.IsDefault)
240241
{
241242
coClass.DefaultMember = memberDeclaration;
242243
}
@@ -292,7 +293,7 @@ private Declaration CreateMemberDeclaration(ComMember member, QualifiedModuleNam
292293
case DeclarationType.PropertyLet:
293294
return new PropertyLetDeclaration(member, parent, module, attributes);
294295
default:
295-
throw new InvalidEnumArgumentException(string.Format("Unexpected DeclarationType {0} encountered.", member.Type));
296+
throw new InvalidEnumArgumentException($"Unexpected DeclarationType {member.Type} encountered.");
296297
}
297298
}
298299

0 commit comments

Comments
 (0)