Skip to content

Not seeing all diagnostics (Unity) #283

@Selmar

Description

@Selmar

I don't see all expected warnings after adding the analyzers to a Unity project. For example, in the below sample code, I only get EPS01 A struct 'NonReadOnlyStruct' can be made readonly.

Perhaps I missed a step?

public struct NonReadOnlyStruct
{
	public readonly long PublicField;
	public long PublicProperty { get; }
	public void PublicMethod() { }

	private static readonly NonReadOnlyStruct _ros;
	public static void Samples(in NonReadOnlyStruct nrs)
	{
		// Ok. Public field access causes no hidden copies
		var x = nrs.PublicField;
		// Ok. No hidden copies.
		x = _ros.PublicField;

		// Hidden copy: Property access on 'in'-parameter
		x = nrs.PublicProperty;

		// Hidden copy: Method call on readonly field
		_ros.PublicMethod();

		ref readonly var local = ref nrs;

		// Hidden copy: method call on ref readonly local
		local.PublicMethod();

		// Hidden copy: method call on ref readonly return
		Local().PublicMethod();

		ref readonly NonReadOnlyStruct Local() => ref _ros;
	}
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions