diff --git a/.github/workflows/ci-matrix.yml b/.github/workflows/ci-matrix.yml index 96d4384e..c343bf04 100644 --- a/.github/workflows/ci-matrix.yml +++ b/.github/workflows/ci-matrix.yml @@ -14,8 +14,8 @@ on: env: DOTNET_CLI_TELEMETRY_OPTOUT: 1 DOTNET_NOLOGO: 1 - UNITY_HASH: 'cc51a95c0300' - UNITY_FULL_VERSION: '6000.2.6f1' + UNITY_HASH: '1c7db571dde0' + UNITY_FULL_VERSION: '6000.3.8f1' HUSKY: 0 jobs: diff --git a/doc/UNT0013.md b/doc/UNT0013.md index 10d024f1..f767c265 100644 --- a/doc/UNT0013.md +++ b/doc/UNT0013.md @@ -1,6 +1,6 @@ # UNT0013 Invalid or redundant SerializeField attribute -The SerializeField attribute is redundant for public fields, and invalid for properties or static/readonly fields. Unlike SerializeReference, the compiler allows you to use the SerializeField attribute on properties, even if it is invalid and will not function in the Unity editor. +The SerializeField attribute is redundant for public fields, and invalid for static/readonly fields. ## Examples of patterns that are flagged by this analyzer @@ -16,9 +16,6 @@ public class SerializedAttributes : MonoBehaviour [SerializeField] // redundant usage public string publicField; - [SerializeField] // invalid usage - private string PrivateProperty { get; set; } - [SerializeField] // invalid usage static string staticField; @@ -42,8 +39,6 @@ public class SerializedAttributes : MonoBehaviour public string publicField; - private string PrivateProperty { get; set; } - static string staticField; readonly field readonlyField; diff --git a/src/Microsoft.Unity.Analyzers.Tests/ImproperSerializeFieldTests.cs b/src/Microsoft.Unity.Analyzers.Tests/ImproperSerializeFieldTests.cs index b6ea740a..2b4035e8 100644 --- a/src/Microsoft.Unity.Analyzers.Tests/ImproperSerializeFieldTests.cs +++ b/src/Microsoft.Unity.Analyzers.Tests/ImproperSerializeFieldTests.cs @@ -90,7 +90,8 @@ class Camera : MonoBehaviour await VerifyCSharpFixAsync(test, fixedTest); } - [Fact] + // starting with Unity 6000.3.x, SerializeField attribute is decorated with [AttributeUsage(AttributeTargets.Field)] + /*[Fact] public async Task InvalidSerializeFieldPropertyTest() { const string test = @" @@ -119,7 +120,7 @@ class Camera : MonoBehaviour "; await VerifyCSharpFixAsync(test, fixedTest); - } + }*/ [Fact] public async Task InvalidSerializeFieldReadonlyTest() diff --git a/src/Microsoft.Unity.Analyzers.Tests/Infrastructure/DiagnosticVerifier.cs b/src/Microsoft.Unity.Analyzers.Tests/Infrastructure/DiagnosticVerifier.cs index f33a5d8a..e4e75c14 100644 --- a/src/Microsoft.Unity.Analyzers.Tests/Infrastructure/DiagnosticVerifier.cs +++ b/src/Microsoft.Unity.Analyzers.Tests/Infrastructure/DiagnosticVerifier.cs @@ -329,11 +329,20 @@ protected static IEnumerable UnityAssemblies() if (!Directory.Exists(installation)) yield break; - var managed = Path.Combine(installation, "Managed"); + var scripting = installation; + var resources = Path.Combine(installation, "Resources"); + // Unity 6000.3.x introduced a new folder structure on MacOS + var macosScripting = Path.Combine(resources, "Scripting"); + + if (OperatingSystem.IsMacOS() && Path.Exists(macosScripting)) + scripting = macosScripting; + + var managed = Path.Combine(scripting, "Managed"); + yield return Path.Combine(managed, "UnityEditor.dll"); yield return Path.Combine(managed, "UnityEngine.dll"); - var monolib = Path.Combine(installation, "MonoBleedingEdge", "lib", "mono", "4.7.1-api"); + var monolib = Path.Combine(scripting, "MonoBleedingEdge", "lib", "mono", "4.7.1-api"); yield return Path.Combine(monolib, "mscorlib.dll"); yield return Path.Combine(monolib, "System.dll"); @@ -341,7 +350,7 @@ protected static IEnumerable UnityAssemblies() yield return Path.Combine(facades, "netstandard.dll"); // Use the 2D template to get additional assemblies, normally acquired through Package Manager - var libcache = Path.Combine(installation, "Resources", "PackageManager", "ProjectTemplates", "libcache"); + var libcache = Path.Combine(resources, "PackageManager", "ProjectTemplates", "libcache"); var template2d = Directory.GetDirectories(libcache, "com.unity.template.2d-*").Single(); var template2dScriptAssemblies = Path.Combine(template2d, "ScriptAssemblies"); diff --git a/src/Microsoft.Unity.Analyzers/BaseVectorConversion.cs b/src/Microsoft.Unity.Analyzers/BaseVectorConversion.cs index c005b5da..d830bd8a 100644 --- a/src/Microsoft.Unity.Analyzers/BaseVectorConversion.cs +++ b/src/Microsoft.Unity.Analyzers/BaseVectorConversion.cs @@ -66,8 +66,17 @@ protected virtual bool CheckForNonAmbiguousReplacement(IObjectCreationOperation if (inOperation.Syntax is not InvocationExpressionSyntax invocation) return true; - var overloads = model.GetMemberGroup(invocation.Expression); - return overloads.Length == 1; + var overloads = model + .GetMemberGroup(invocation.Expression) + .OfType(); + + // With Unity 6000.3.x, Unity introduced overloads with -in- specifiers for performance + // So we consider overloads as distinct only when their parameter types differ (ignoring specifiers) + var distinctSignatures = overloads + .GroupBy(m => string.Join(",", m.Parameters.Select(p => p.Type.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat)))) + .Count(); + + return distinctSignatures == 1; } protected virtual bool CheckArguments(IObjectCreationOperation ocOperation)