Skip to content

Commit

Permalink
fixes type resolution resolving to non existing Assembly.MainModule.T…
Browse files Browse the repository at this point in the history
…ypeSystem members (#277)
  • Loading branch information
adrianoc committed Apr 11, 2024
1 parent d75ff46 commit 4bcdc2b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
13 changes: 13 additions & 0 deletions Cecilifier.Core.Tests/Tests/Unit/TypeResolutionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,19 @@ public void GenericTypeParameterInTopLevelMethod(string code, string testSpecifi
Does.Match(testSpecificExpectation));
}

[TestCase("DateTime field;", TestName = "Field")]
[TestCase("DateTime Prop { get => default(DateTime); }", TestName = "Property")]
[TestCase("DateTime M() => default(DateTime);", TestName = "Method return type")]
[TestCase("void M(DateTime d) {}", TestName = "Parameter")]
[TestCase("void M() { DateTime d; }", TestName = "Local variable")]
[TestCase("void M() { Action<DateTime> d; }", TestName = "Local variable (generic)")]
[TestCase("void M() { Delegate d; }", TestName = "Delegate")]
public void TestTypeResolution_Issue277(string memberDefinition)
{
var result = RunCecilifier($$"""using System; class C { {{memberDefinition}} }""");
Assert.That(result.GeneratedCode.ReadToEnd(), Does.Not.Match(@"assembly\.MainModule\.TypeSystem\.DateTime"));
}

private static IEnumerable ExternalTypeTestScenarios()
{
const string fieldTemplate = @"using System.Collections; class Foo {{ {0} field; }}";
Expand Down
10 changes: 8 additions & 2 deletions Cecilifier.Core/Misc/TypeResolverImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,14 @@ private string ResolvePredefinedAndComposedTypes(ITypeSymbol type)
{
return CecilDefinitionsFactory.FunctionPointerType(this, functionPointer);
}

if (type.SpecialType == SpecialType.None || type.SpecialType == SpecialType.System_Enum || type.SpecialType == SpecialType.System_ValueType || type.SpecialType == SpecialType.System_Decimal || type.TypeKind == TypeKind.Interface)

if (type.SpecialType == SpecialType.None
|| type.SpecialType == SpecialType.System_Enum
|| type.SpecialType == SpecialType.System_ValueType
|| type.SpecialType == SpecialType.System_Decimal
|| type.SpecialType == SpecialType.System_DateTime
|| type.SpecialType == SpecialType.System_Delegate
|| type.TypeKind == TypeKind.Interface)
{
return null;
}
Expand Down

0 comments on commit 4bcdc2b

Please sign in to comment.