Skip to content

Commit

Permalink
Fix false positive in NoDefaultConstructorIssue for static constructors.
Browse files Browse the repository at this point in the history
  • Loading branch information
dgrunwald committed Jul 9, 2013
1 parent 90d6545 commit d87a233
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ public override void VisitConstructorDeclaration(ConstructorDeclaration declarat
var result = ctx.Resolve(declaration) as MemberResolveResult;
if (result == null || result.IsError)
return;
if (result.Member.IsStatic)
return; // ignore static ctor

var baseType = result.Member.DeclaringType.DirectBaseTypes.FirstOrDefault(t => !t.IsKnownType(KnownTypeCode.Object) && t.Kind != TypeKind.Interface);

Expand Down
2 changes: 1 addition & 1 deletion ICSharpCode.NRefactory.Cecil/CecilLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,7 @@ void AddAttributes(MethodDefinition methodDefinition, IList<IUnresolvedAttribute
switch (info.Attributes & PInvokeAttributes.CallConvMask) {
case (PInvokeAttributes)0:
Debug.WriteLine ("P/Invoke calling convention not set on:" + methodDefinition.FullName);
callingConvention = CallingConvention.StdCall;
callingConvention = 0;
break;
case PInvokeAttributes.CallConvCdecl:
callingConvention = CallingConvention.Cdecl;
Expand Down
2 changes: 1 addition & 1 deletion ICSharpCode.NRefactory.IKVM/IkvmLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ void AddAttributes(MethodInfo methodDefinition, IList<IUnresolvedAttribute> attr
switch (flags & ImplMapFlags.CallConvMask) {
case (ImplMapFlags)0:
Debug.WriteLine ("P/Invoke calling convention not set on:" + methodDefinition.Name);
callingConvention = CallingConvention.StdCall;
callingConvention = 0;
break;
case ImplMapFlags.CallConvCdecl:
callingConvention = CallingConvention.Cdecl;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,65 @@ public A() {}
Assert.AreEqual("CS1729: The type 'B' does not contain a constructor that takes '0' arguments", issues.ElementAt(1).Description);
Assert.AreEqual("CS1729: The type 'D' does not contain a constructor that takes '0' arguments", issues.ElementAt(0).Description);
}

[Test]
[Ignore("Fix me")]
public void ShouldNotReturnIssueIfBaseClassCtorHasOptionalParameters()
{
var testInput =
@"class BaseClass
{
public BaseClass(int i = 0)
{
}
}
class ChildClass : BaseClass
{
}";

Test<NoDefaultConstructorIssue>(testInput, 0);
}

[Test]
[Ignore("Fix me")]
public void ShouldNotReturnIssueIfBaseClassCtorHasVariadicParameters()
{
var testInput =
@"class BaseClass
{
public BaseClass(params string[] str)
{
}
}
class ChildClass : BaseClass
{
}";

Test<NoDefaultConstructorIssue>(testInput, 0);
}

[Test]
public void ShouldNotReturnIssueForStaticConstructor()
{
var testInput =
@"class BaseClass
{
public BaseClass(string text)
{
}
}
class ChildClass : BaseClass
{
public ChildClass() : base(""text"") {}
static ChildClass() {}
}";

Test<NoDefaultConstructorIssue>(testInput, 0);
}
}
}

4 changes: 4 additions & 0 deletions Packages/ICSharpCode.NRefactory.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,17 @@
<file src="..\bin\Release\ICSharpCode.NRefactory.dll" target="lib\Net40" />
<file src="..\bin\Release\ICSharpCode.NRefactory.pdb" target="lib\Net40" />
<file src="..\bin\Release\ICSharpCode.NRefactory.xml" target="lib\Net40" />
<file src="..\bin\Release\ICSharpCode.NRefactory.Cecil.dll" target="lib\Net40" />
<file src="..\bin\Release\ICSharpCode.NRefactory.Cecil.pdb" target="lib\Net40" />
<file src="..\bin\Release\ICSharpCode.NRefactory.Cecil.xml" target="lib\Net40" />
<file src="..\bin\Release\ICSharpCode.NRefactory.CSharp.dll" target="lib\Net40" />
<file src="..\bin\Release\ICSharpCode.NRefactory.CSharp.pdb" target="lib\Net40" />
<file src="..\bin\Release\ICSharpCode.NRefactory.CSharp.xml" target="lib\Net40" />
<file src="..\bin\Release\ICSharpCode.NRefactory.Xml.dll" target="lib\Net40" />
<file src="..\bin\Release\ICSharpCode.NRefactory.Xml.pdb" target="lib\Net40" />
<file src="..\bin\Release\ICSharpCode.NRefactory.Xml.xml" target="lib\Net40" />
<file src="..\ICSharpCode.NRefactory\**\*.cs" target="src\ICSharpCode.NRefactory" />
<file src="..\ICSharpCode.NRefactory.Cecil\**\*.cs" target="src\ICSharpCode.NRefactory" />
<file src="..\ICSharpCode.NRefactory.CSharp\**\*.cs" target="src\ICSharpCode.NRefactory.CSharp" />
<file src="..\ICSharpCode.NRefactory.CSharp\**\*.jay" target="src\ICSharpCode.NRefactory.CSharp" />
<file src="..\ICSharpCode.NRefactory.Xml\**\*.cs" target="src\ICSharpCode.NRefactory.Xml" />
Expand Down

0 comments on commit d87a233

Please sign in to comment.