Skip to content
This repository has been archived by the owner on Sep 24, 2020. It is now read-only.

Fixed member lookup in static context #445

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -14,7 +14,7 @@
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<OutputPath>..\bin\Debug\</OutputPath>
<DefineConstants>DEBUG;</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
Expand All @@ -23,7 +23,7 @@
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>none</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Release\</OutputPath>
<OutputPath>..\bin\Release\</OutputPath>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Externalconsole>true</Externalconsole>
Expand All @@ -32,7 +32,7 @@
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\net_4_5_Debug\</OutputPath>
<OutputPath>..\bin\net_4_5_Debug\</OutputPath>
<DefineConstants>DEBUG;</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
Expand All @@ -42,7 +42,7 @@
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'net_4_5_Release|AnyCPU' ">
<DebugType>none</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\net_4_5_Release\</OutputPath>
<OutputPath>..\bin\net_4_5_Release\</OutputPath>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Externalconsole>true</Externalconsole>
Expand Down
4 changes: 3 additions & 1 deletion ICSharpCode.NRefactory.CSharp/Resolver/MemberLookup.cs
Expand Up @@ -348,10 +348,12 @@ public ResolveResult Lookup(ResolveResult targetResolveResult, string name, ILis
Predicate<ITypeDefinition> nestedTypeFilter = delegate(ITypeDefinition entity) {
return entity.Name == name && IsAccessible(entity, allowProtectedAccess);
};
bool isStaticContext = targetResolveResult is TypeResolveResult;
Predicate<IUnresolvedMember> memberFilter = delegate(IUnresolvedMember entity) {
// NOTE: Atm destructors can be looked up with 'Finalize'
return entity.SymbolKind != SymbolKind.Indexer &&
entity.SymbolKind != SymbolKind.Operator &&
entity.SymbolKind != SymbolKind.Operator &&
(!isStaticContext || entity.IsStatic) &&
entity.Name == name;
};

Expand Down
12 changes: 8 additions & 4 deletions ICSharpCode.NRefactory.Cecil/ICSharpCode.NRefactory.Cecil.csproj
Expand Up @@ -23,39 +23,43 @@
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug</OutputPath>
<OutputPath>..\bin\Debug\</OutputPath>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<ConsolePause>false</ConsolePause>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<DocumentationFile>..\bin\Debug\ICSharpCode.NRefactory.Cecil.xml</DocumentationFile>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>PdbOnly</DebugType>
<Optimize>True</Optimize>
<OutputPath>bin\Release</OutputPath>
<OutputPath>..\bin\Release\</OutputPath>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<ConsolePause>false</ConsolePause>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<DocumentationFile>..\bin\Release\ICSharpCode.NRefactory.Cecil.xml</DocumentationFile>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'net_4_5_Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug</OutputPath>
<OutputPath>..\bin\net_4_5_Debug\</OutputPath>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<ConsolePause>false</ConsolePause>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<DocumentationFile>..\bin\net_4_5_Debug\ICSharpCode.NRefactory.Cecil.xml</DocumentationFile>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'net_4_5_Release|AnyCPU' ">
<DebugType>full</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release</OutputPath>
<OutputPath>..\bin\net_4_5_Release\</OutputPath>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<ConsolePause>false</ConsolePause>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<DocumentationFile>..\bin\net_4_5_Release\ICSharpCode.NRefactory.Cecil.xml</DocumentationFile>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<DefineConstants>DEBUG;</DefineConstants>
Expand Down
Expand Up @@ -70,15 +70,19 @@
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<OutputPath>..\bin\Debug\</OutputPath>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<OutputPath>..\bin\Release\</OutputPath>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'net_4_5_Debug|AnyCPU' ">
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<OutputPath>..\bin\net_4_5_Debug\</OutputPath>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'net_4_5_Release|AnyCPU' ">
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<OutputPath>..\bin\net_4_5_Release\</OutputPath>
</PropertyGroup>
<ItemGroup>
<Reference Include="Microsoft.Build" />
Expand Down
Expand Up @@ -14,7 +14,7 @@
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug</OutputPath>
<OutputPath>..\bin\Debug\</OutputPath>
<DefineConstants>DEBUG;</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
Expand All @@ -23,7 +23,7 @@
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>none</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Release</OutputPath>
<OutputPath>..\bin\Release\</OutputPath>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<ConsolePause>false</ConsolePause>
Expand All @@ -32,7 +32,7 @@
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug</OutputPath>
<OutputPath>..\bin\net_4_5_Debug\</OutputPath>
<DefineConstants>DEBUG;</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
Expand All @@ -42,7 +42,7 @@
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'net_4_5_Release|AnyCPU' ">
<DebugType>none</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Release</OutputPath>
<OutputPath>..\bin\net_4_5_Release\</OutputPath>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<ConsolePause>false</ConsolePause>
Expand Down
16 changes: 8 additions & 8 deletions ICSharpCode.NRefactory.IKVM/ICSharpCode.NRefactory.IKVM.csproj
Expand Up @@ -16,41 +16,41 @@
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug</OutputPath>
<OutputPath>..\bin\Debug\</OutputPath>
<DefineConstants>DEBUG;</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<ConsolePause>false</ConsolePause>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>full</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release</OutputPath>
<OutputPath>..\bin\Release\</OutputPath>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<ConsolePause>false</ConsolePause>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'net_4_5_Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug</OutputPath>
<OutputPath>..\bin\net_4_5_Debug\</OutputPath>
<DefineConstants>DEBUG;</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<ConsolePause>false</ConsolePause>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'net_4_5_Release|AnyCPU' ">
<DebugType>full</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release</OutputPath>
<OutputPath>..\bin\net_4_5_Release\</OutputPath>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<ConsolePause>false</ConsolePause>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
Expand Down
Expand Up @@ -945,7 +945,6 @@ class TestClass
int M() { return 0; }
string TestMethod()
{
object o = TestClass.i;
object p = i;
object q = M();
object m = this[0];
Expand All @@ -959,7 +958,6 @@ string TestMethod()

var lastStatement = method.Body.Statements.Last();

Assert.AreEqual(NullValueStatus.DefinitelyNotNull, analysis.GetVariableStatusAfterStatement(lastStatement, "o"));
Assert.AreEqual(NullValueStatus.DefinitelyNotNull, analysis.GetVariableStatusAfterStatement(lastStatement, "p"));
Assert.AreEqual(NullValueStatus.DefinitelyNotNull, analysis.GetVariableStatusAfterStatement(lastStatement, "q"));
Assert.AreEqual(NullValueStatus.DefinitelyNotNull, analysis.GetVariableStatusAfterStatement(lastStatement, "m"));
Expand Down
29 changes: 29 additions & 0 deletions ICSharpCode.NRefactory.Tests/CSharp/Resolver/MemberLookupTests.cs
Expand Up @@ -208,6 +208,35 @@ class Test {
Assert.AreEqual("Test.F", rr.Member.FullName);
Assert.IsInstanceOf<TypeResolveResult>(rr.TargetResult);
}

[Test]
public void InstanceMethodCallInStaticContext()
{
string program = @"using System;
class Test {
void F() {}
public void M() {
$Test.F()$;
}
}";
var rr = Resolve<UnknownMethodResolveResult>(program);
}

[Test]
public void ConstField()
{
string program = @"using System;
class Test {
const int C = 1;
public int M() {
return $Test.C$;
}
}";
var rr = Resolve<MemberResolveResult>(program);
Assert.AreEqual("Test.C", rr.Member.FullName);
Assert.IsInstanceOf<TypeResolveResult>(rr.TargetResult);
}


[Test]
public void TestOuterTemplateParameter()
Expand Down
Expand Up @@ -138,6 +138,7 @@ public void Overloaded()
}

[Test]
[Ignore("Test should be method with no associated instance expression. C# 5.0 spec �7.6.4")]
public void MethodInGenericInterface()
{
Assert.AreEqual("M:IGeneric`2.Test``1(``0[0:,0:]@)",
Expand Down
Expand Up @@ -87,7 +87,7 @@
<Reference Include="System.Xml" />
<Reference Include="System.Xml.Linq" />
<Reference Include="nunit.framework">
<HintPath>..\..\cecil\Test\libs\nunit-2.5.10\nunit.framework.dll</HintPath>
<HintPath>..\..\cecil\Test\libs\nunit-2.6.2\nunit.framework.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
Expand Down