Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,14 @@ public override MultiValue VisitInstanceReference (IInstanceReferenceOperation i

public override MultiValue VisitFieldReference (IFieldReferenceOperation fieldRef, StateValue state)
{
return fieldRef.Field.Type.IsTypeInterestingForDataflow () ? new FieldValue (fieldRef.Field) : TopValue;
if (!fieldRef.Field.Type.IsTypeInterestingForDataflow ())
return TopValue;

var field = fieldRef.Field;
if (field.Name is "Empty" && field.ContainingType.HasName ("System.String"))
return new KnownStringValue (string.Empty);

return new FieldValue (fieldRef.Field);
}

public override MultiValue VisitTypeOf (ITypeOfOperation typeOfOperation, StateValue state)
Expand Down
5 changes: 3 additions & 2 deletions test/ILLink.RoslynAnalyzer.Tests/DataFlowTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,11 @@ public Task GetNestedTypeOnAllAnnotatedType ()
return RunTest (allowMissingWarnings: true);
}

[Fact (Skip = "https://github.com/dotnet/linker/issues/2273")]
[Fact]
public Task GetTypeDataFlow ()
{
return RunTest (nameof (GetTypeDataFlow));
// https://github.com/dotnet/linker/issues/2273
return RunTest (allowMissingWarnings: true);
}

[Fact]
Expand Down
13 changes: 13 additions & 0 deletions test/Mono.Linker.Tests.Cases/DataFlow/FieldDataFlow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ public static void Main ()
instance.WriteUnknownValue ();

_ = _annotationOnWrongType;

TestStringEmpty ();
}

[DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)]
Expand Down Expand Up @@ -148,6 +150,17 @@ static void MakeArrayValuesUnknown (object[] array)
}
}

private static void TestStringEmpty ()
{
RequirePublicMethods (string.Empty);
}

private static void RequirePublicMethods (
[DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicMethods)]
string s)
{
}

private static void RequirePublicParameterlessConstructor (
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)]
Type type)
Expand Down