Browse Source

Code completion: Handle implicit conversion of "null" to all reference types and Nullable<T>.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@2950 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Daniel Grunwald 18 years ago
parent
commit
6667e3fbdb
  1. 18
      src/Main/Base/Test/MemberLookupHelperTests.cs
  2. 12
      src/Main/Base/Test/OverloadFinding.cs
  3. 16
      src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/MemberLookupHelper.cs

18
src/Main/Base/Test/MemberLookupHelperTests.cs

@ -153,6 +153,24 @@ namespace ICSharpCode.SharpDevelop.Tests @@ -153,6 +153,24 @@ namespace ICSharpCode.SharpDevelop.Tests
Assert.AreEqual("System.Windows.Forms.ToolStripItem", res.FullyQualifiedName);
}
[Test]
public void GetCommonTypeOfStringAndNull()
{
IReturnType res = MemberLookupHelper.GetCommonType(msc,
msc.GetClass("System.String", 0).DefaultReturnType,
NullReturnType.Instance);
Assert.AreEqual("System.String", res.FullyQualifiedName);
}
[Test]
public void GetCommonTypeOfNullAndString()
{
IReturnType res = MemberLookupHelper.GetCommonType(msc,
NullReturnType.Instance,
msc.GetClass("System.String", 0).DefaultReturnType);
Assert.AreEqual("System.String", res.FullyQualifiedName);
}
[Test]
public void GetTypeInheritanceTreeOfClassDerivingFromListOfString()
{

12
src/Main/Base/Test/OverloadFinding.cs

@ -47,6 +47,18 @@ namespace ICSharpCode.SharpDevelop.Tests @@ -47,6 +47,18 @@ namespace ICSharpCode.SharpDevelop.Tests
Test("(long.MaxValue)", 0, overloads);
}
[Test] public void NullForReferenceTypes()
{
string[] overloads = {"(int a)", "(string a)"};
Test("(null)", 1, overloads);
}
[Test] public void NullForNullableType()
{
string[] overloads = {"(int a)", "(int? a)"};
Test("(null)", 1, overloads);
}
NRefactoryResolverTests nrrt = new NRefactoryResolverTests();
void Test(string callExpr, int num, params string[] signatures)

16
src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/MemberLookupHelper.cs

@ -691,8 +691,6 @@ namespace ICSharpCode.SharpDevelop.Dom @@ -691,8 +691,6 @@ namespace ICSharpCode.SharpDevelop.Dom
public static bool IsApplicable(IReturnType argument, IReturnType expected)
{
if (argument == null || argument == NullReturnType.Instance)
return true; // "null" can be passed for any argument
return ConversionExistsInternal(argument, expected, true);
}
#endregion
@ -748,6 +746,20 @@ namespace ICSharpCode.SharpDevelop.Dom @@ -748,6 +746,20 @@ namespace ICSharpCode.SharpDevelop.Dom
if (toIsDefault && to.FullyQualifiedName == "System.Object") {
return true; // from any type to object
}
if (from == NullReturnType.Instance) {
IClass toClass = to.GetUnderlyingClass();
if (toClass != null) {
switch (toClass.ClassType) {
case ClassType.Class:
case ClassType.Delegate:
case ClassType.Interface:
return true;
case ClassType.Struct:
return toClass.FullyQualifiedName == "System.Nullable";
}
}
return false;
}
if ((toIsDefault || to.IsConstructedReturnType || to.IsGenericReturnType)
&& (fromIsDefault || from.IsArrayReturnType || from.IsConstructedReturnType))

Loading…
Cancel
Save