Skip to content

Commit

Permalink
Fix for source-build stage 2 compiler errors (#43879)
Browse files Browse the repository at this point in the history
  • Loading branch information
NikolaMilosavljevic authored Oct 4, 2024
1 parent 400deeb commit 49e5d17
Show file tree
Hide file tree
Showing 3 changed files with 351 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Nikola Milosavljevic <[email protected]>
Date: Thu, 3 Oct 2024 19:06:30 +0000
Subject: [PATCH] Update field references

Backport: https://github.com/dotnet/roslyn-analyzers/pull/7430
---
.../FlowAnalysis/Framework/DataFlow/AnalysisEntity.cs | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/Utilities/FlowAnalysis/FlowAnalysis/Framework/DataFlow/AnalysisEntity.cs b/src/Utilities/FlowAnalysis/FlowAnalysis/Framework/DataFlow/AnalysisEntity.cs
index 5a69abfa0..20553be25 100644
--- a/src/Utilities/FlowAnalysis/FlowAnalysis/Framework/DataFlow/AnalysisEntity.cs
+++ b/src/Utilities/FlowAnalysis/FlowAnalysis/Framework/DataFlow/AnalysisEntity.cs
@@ -186,8 +186,8 @@ internal bool ShouldBeTrackedForAnalysis(bool hasCompletePointsToAnalysisResult)

public bool HasConstantValue => Symbol switch
{
- IFieldSymbol field => field.HasConstantValue,
- ILocalSymbol local => local.HasConstantValue,
+ IFieldSymbol fieldSymbol => fieldSymbol.HasConstantValue,
+ ILocalSymbol localSymbol => localSymbol.HasConstantValue,
_ => false,
};

Original file line number Diff line number Diff line change
@@ -0,0 +1,301 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Nikola Milosavljevic <[email protected]>
Date: Thu, 3 Oct 2024 18:08:04 +0000
Subject: [PATCH] Update field references in property accessors

Backport: https://github.com/dotnet/runtime/pull/108222
---
.../Common/TypeDesc.TypeEquivalence.cs | 8 ++++----
.../tools/Common/TypeSystem/Common/TypeDesc.cs | 6 +++---
.../tools/Common/TypeSystem/Ecma/EcmaType.cs | 6 +++---
.../Common/src/System/Net/CookieParser.cs | 12 ++++++------
.../RuntimeBinder/Semantics/Symbols/Symbol.cs | 4 ++--
.../System/Runtime/Serialization/DataMember.cs | 4 ++--
.../src/System/Xml/Serialization/Models.cs | 4 ++--
.../tests/TypeTests.cs | 8 ++++----
.../tests/SerializationTestTypes/DataContract.cs | 6 +++---
...dynamic.context.operator.compound.event.+=.cs | 8 ++++----
...dynamic.context.operator.compound.event.-=.cs | 16 ++++++++--------
11 files changed, 41 insertions(+), 41 deletions(-)

diff --git a/src/coreclr/tools/Common/TypeSystem/Common/TypeDesc.TypeEquivalence.cs b/src/coreclr/tools/Common/TypeSystem/Common/TypeDesc.TypeEquivalence.cs
index 3ae8c0f2a5f..8c5e22b735b 100644
--- a/src/coreclr/tools/Common/TypeSystem/Common/TypeDesc.TypeEquivalence.cs
+++ b/src/coreclr/tools/Common/TypeSystem/Common/TypeDesc.TypeEquivalence.cs
@@ -136,20 +136,20 @@ public bool TypeHasCharacteristicsRequiredToBeLoadableTypeEquivalentType
return false;
}

- foreach (var field in GetFields())
+ foreach (var fieldInfo in GetFields())
{
- if (field.IsLiteral)
+ if (fieldInfo.IsLiteral)
{
// Literal fields are ok
continue;
}

- if (field.IsStatic)
+ if (fieldInfo.IsStatic)
{
return false;
}

- if (field.GetEffectiveVisibility() != EffectiveVisibility.Public)
+ if (fieldInfo.GetEffectiveVisibility() != EffectiveVisibility.Public)
{
return false;
}
diff --git a/src/coreclr/tools/Common/TypeSystem/Common/TypeDesc.cs b/src/coreclr/tools/Common/TypeSystem/Common/TypeDesc.cs
index 00dd1f70d4a..c390e9eba5b 100644
--- a/src/coreclr/tools/Common/TypeSystem/Common/TypeDesc.cs
+++ b/src/coreclr/tools/Common/TypeSystem/Common/TypeDesc.cs
@@ -472,10 +472,10 @@ public virtual TypeDesc UnderlyingType
if (!this.IsEnum)
return this;

- foreach (var field in this.GetFields())
+ foreach (var fieldInfo in this.GetFields())
{
- if (!field.IsStatic)
- return field.FieldType;
+ if (!fieldInfo.IsStatic)
+ return fieldInfo.FieldType;
}

ThrowHelper.ThrowTypeLoadException(ExceptionStringID.ClassLoadGeneral, this);
diff --git a/src/coreclr/tools/Common/TypeSystem/Ecma/EcmaType.cs b/src/coreclr/tools/Common/TypeSystem/Ecma/EcmaType.cs
index 239537bbd09..3c349b3615c 100644
--- a/src/coreclr/tools/Common/TypeSystem/Ecma/EcmaType.cs
+++ b/src/coreclr/tools/Common/TypeSystem/Ecma/EcmaType.cs
@@ -464,9 +464,9 @@ public override TypeDesc UnderlyingType

foreach (var handle in _typeDefinition.GetFields())
{
- var field = _module.GetField(handle, this);
- if (!field.IsStatic)
- return field.FieldType;
+ var fieldInfo = _module.GetField(handle, this);
+ if (!fieldInfo.IsStatic)
+ return fieldInfo.FieldType;
}

return base.UnderlyingType; // Use the base implementation to get consistent error behavior
diff --git a/src/libraries/Common/src/System/Net/CookieParser.cs b/src/libraries/Common/src/System/Net/CookieParser.cs
index 9148b479a1f..3cc3826457b 100644
--- a/src/libraries/Common/src/System/Net/CookieParser.cs
+++ b/src/libraries/Common/src/System/Net/CookieParser.cs
@@ -553,9 +553,9 @@ private static FieldInfo IsQuotedDomainField
if (s_isQuotedDomainField == null)
{
// TODO https://github.com/dotnet/runtime/issues/19348:
- FieldInfo? field = typeof(Cookie).GetField("IsQuotedDomain", BindingFlags.Instance | BindingFlags.NonPublic);
- Debug.Assert(field != null, "We need to use an internal field named IsQuotedDomain that is declared on Cookie.");
- s_isQuotedDomainField = field;
+ FieldInfo? fieldInfo = typeof(Cookie).GetField("IsQuotedDomain", BindingFlags.Instance | BindingFlags.NonPublic);
+ Debug.Assert(fieldInfo != null, "We need to use an internal field named IsQuotedDomain that is declared on Cookie.");
+ s_isQuotedDomainField = fieldInfo;
}

return s_isQuotedDomainField;
@@ -570,9 +570,9 @@ private static FieldInfo IsQuotedVersionField
if (s_isQuotedVersionField == null)
{
// TODO https://github.com/dotnet/runtime/issues/19348:
- FieldInfo? field = typeof(Cookie).GetField("IsQuotedVersion", BindingFlags.Instance | BindingFlags.NonPublic);
- Debug.Assert(field != null, "We need to use an internal field named IsQuotedVersion that is declared on Cookie.");
- s_isQuotedVersionField = field;
+ FieldInfo? fieldInfo = typeof(Cookie).GetField("IsQuotedVersion", BindingFlags.Instance | BindingFlags.NonPublic);
+ Debug.Assert(fieldInfo != null, "We need to use an internal field named IsQuotedVersion that is declared on Cookie.");
+ s_isQuotedVersionField = fieldInfo;
}

return s_isQuotedVersionField;
diff --git a/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/Semantics/Symbols/Symbol.cs b/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/Semantics/Symbols/Symbol.cs
index d00a64dbb78..3594515245e 100644
--- a/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/Semantics/Symbols/Symbol.cs
+++ b/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/Semantics/Symbols/Symbol.cs
@@ -131,9 +131,9 @@ public bool isStatic
{
get
{
- if (this is FieldSymbol field)
+ if (this is FieldSymbol fieldInfo)
{
- return field.isStatic;
+ return fieldInfo.isStatic;
}

if (this is EventSymbol ev)
diff --git a/src/libraries/System.Private.DataContractSerialization/src/System/Runtime/Serialization/DataMember.cs b/src/libraries/System.Private.DataContractSerialization/src/System/Runtime/Serialization/DataMember.cs
index c06fc829069..5c07f7d8265 100644
--- a/src/libraries/System.Private.DataContractSerialization/src/System/Runtime/Serialization/DataMember.cs
+++ b/src/libraries/System.Private.DataContractSerialization/src/System/Runtime/Serialization/DataMember.cs
@@ -170,8 +170,8 @@ internal Type MemberType
{
if (_memberType == null)
{
- if (MemberInfo is FieldInfo field)
- _memberType = field.FieldType;
+ if (MemberInfo is FieldInfo fieldInfo)
+ _memberType = fieldInfo.FieldType;
else if (MemberInfo is PropertyInfo prop)
_memberType = prop.PropertyType;
else
diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Serialization/Models.cs b/src/libraries/System.Private.Xml/src/System/Xml/Serialization/Models.cs
index 2f3d20c19f4..9319de05d7d 100644
--- a/src/libraries/System.Private.Xml/src/System/Xml/Serialization/Models.cs
+++ b/src/libraries/System.Private.Xml/src/System/Xml/Serialization/Models.cs
@@ -431,8 +431,8 @@ internal ConstantModel[] Constants
FieldInfo[] fields = Type.GetFields();
for (int i = 0; i < fields.Length; i++)
{
- FieldInfo field = fields[i];
- ConstantModel? constant = GetConstantModel(field);
+ FieldInfo fieldInfo = fields[i];
+ ConstantModel? constant = GetConstantModel(fieldInfo);
if (constant != null) list.Add(constant);
}
_constants = list.ToArray();
diff --git a/src/libraries/System.Reflection.TypeExtensions/tests/TypeTests.cs b/src/libraries/System.Reflection.TypeExtensions/tests/TypeTests.cs
index 20f91ef81bf..f8ca55d2058 100644
--- a/src/libraries/System.Reflection.TypeExtensions/tests/TypeTests.cs
+++ b/src/libraries/System.Reflection.TypeExtensions/tests/TypeTests.cs
@@ -792,8 +792,8 @@ public class GenericClassWithVarArgMethod<T>

public T publicField
{
- get { return field; }
- set { field = value; }
+ get { return this.field; }
+ set { this.field = value; }
}

public T ReturnAndSetField(T newFieldValue, params T[] moreFieldValues)
@@ -815,8 +815,8 @@ public class ClassWithVarArgMethod

public int publicField
{
- get { return field; }
- set { field = value; }
+ get { return this.field; }
+ set { this.field = value; }
}

public int ReturnAndSetField(int newFieldValue, params int[] moreFieldValues)
diff --git a/src/libraries/System.Runtime.Serialization.Xml/tests/SerializationTestTypes/DataContract.cs b/src/libraries/System.Runtime.Serialization.Xml/tests/SerializationTestTypes/DataContract.cs
index 91e57848757..c6294487326 100644
--- a/src/libraries/System.Runtime.Serialization.Xml/tests/SerializationTestTypes/DataContract.cs
+++ b/src/libraries/System.Runtime.Serialization.Xml/tests/SerializationTestTypes/DataContract.cs
@@ -1057,9 +1057,9 @@ public Type MemberType
{
get
{
- FieldInfo field = MemberInfo as FieldInfo;
- if (field != null)
- return field.FieldType;
+ FieldInfo fieldInfo = MemberInfo as FieldInfo;
+ if (fieldInfo != null)
+ return fieldInfo.FieldType;
return ((PropertyInfo)MemberInfo).PropertyType;
}
}
diff --git a/src/libraries/System.Runtime/tests/System.Dynamic.Runtime.Tests/Dynamic.Context/Conformance.dynamic.context.operator.compound.event.+=.cs b/src/libraries/System.Runtime/tests/System.Dynamic.Runtime.Tests/Dynamic.Context/Conformance.dynamic.context.operator.compound.event.+=.cs
index 9fc58b8a5c8..8777fc77537 100644
--- a/src/libraries/System.Runtime/tests/System.Dynamic.Runtime.Tests/Dynamic.Context/Conformance.dynamic.context.operator.compound.event.+=.cs
+++ b/src/libraries/System.Runtime/tests/System.Dynamic.Runtime.Tests/Dynamic.Context/Conformance.dynamic.context.operator.compound.event.+=.cs
@@ -302,12 +302,12 @@ public Dele Field
{
get
{
- return field;
+ return this.field;
}

set
{
- field = value;
+ this.field = value;
}
}

@@ -372,12 +372,12 @@ public Dele Field
{
get
{
- return field;
+ return this.field;
}

set
{
- field = value;
+ this.field = value;
}
}

diff --git a/src/libraries/System.Runtime/tests/System.Dynamic.Runtime.Tests/Dynamic.Context/Conformance.dynamic.context.operator.compound.event.-=.cs b/src/libraries/System.Runtime/tests/System.Dynamic.Runtime.Tests/Dynamic.Context/Conformance.dynamic.context.operator.compound.event.-=.cs
index 59ddeda115b..64373f13eb3 100644
--- a/src/libraries/System.Runtime/tests/System.Dynamic.Runtime.Tests/Dynamic.Context/Conformance.dynamic.context.operator.compound.event.-=.cs
+++ b/src/libraries/System.Runtime/tests/System.Dynamic.Runtime.Tests/Dynamic.Context/Conformance.dynamic.context.operator.compound.event.-=.cs
@@ -776,12 +776,12 @@ public Dele Field
{
get
{
- return field;
+ return this.field;
}

set
{
- field = value;
+ this.field = value;
}
}

@@ -864,12 +864,12 @@ public Dele Field
{
get
{
- return field;
+ return this.field;
}

set
{
- field = value;
+ this.field = value;
}
}

@@ -952,12 +952,12 @@ public Dele Field
{
get
{
- return field;
+ return this.field;
}

set
{
- field = value;
+ this.field = value;
}
}

@@ -1041,12 +1041,12 @@ public Dele Field
{
get
{
- return field;
+ return this.field;
}

set
{
- field = value;
+ this.field = value;
}
}

25 changes: 25 additions & 0 deletions src/SourceBuild/patches/vstest/0001-Auto-property-suggestion.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Nikola Milosavljevic <[email protected]>
Date: Thu, 3 Oct 2024 19:13:43 +0000
Subject: [PATCH] Auto property suggestion

Backport: https://github.com/microsoft/vstest/pull/10365
---
.editorconfig | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/.editorconfig b/.editorconfig
index b78e7a35b..39f9dc14c 100644
--- a/.editorconfig
+++ b/.editorconfig
@@ -105,8 +105,8 @@ dotnet_style_prefer_compound_assignment = true:warning # not default, default i
dotnet_diagnostic.IDE0074.severity = warning # not default, set in accordance to previous setting

# IDE0032: Use auto property
-dotnet_style_prefer_auto_properties = true:warning # not default, default is true:suggestion, increased severity to ensure it is used
-dotnet_diagnostic.IDE0032.severity = warning # not default, set in accordance to previous setting
+dotnet_style_prefer_auto_properties = true:suggestion # not default, default is true:suggestion, increased severity to ensure it is used
+dotnet_diagnostic.IDE0032.severity = suggestion # not default, set in accordance to previous setting

# Field preferences
dotnet_style_readonly_field = true:warning

0 comments on commit 49e5d17

Please sign in to comment.