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
4 changes: 2 additions & 2 deletions .github/workflows/ci-matrix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
7 changes: 1 addition & 6 deletions doc/UNT0013.md
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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;

Expand All @@ -42,8 +39,6 @@ public class SerializedAttributes : MonoBehaviour

public string publicField;

private string PrivateProperty { get; set; }

static string staticField;

readonly field readonlyField;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = @"
Expand Down Expand Up @@ -119,7 +120,7 @@ class Camera : MonoBehaviour
";

await VerifyCSharpFixAsync(test, fixedTest);
}
}*/

[Fact]
public async Task InvalidSerializeFieldReadonlyTest()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -329,19 +329,28 @@ protected static IEnumerable<string> 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");

var facades = Path.Combine(monolib, "Facades");
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");

Expand Down
13 changes: 11 additions & 2 deletions src/Microsoft.Unity.Analyzers/BaseVectorConversion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<IMethodSymbol>();

// 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)
Expand Down
Loading