Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not seeing all diagnostics (Unity) #283

Open
Selmar opened this issue Mar 31, 2024 · 1 comment
Open

Not seeing all diagnostics (Unity) #283

Selmar opened this issue Mar 31, 2024 · 1 comment

Comments

@Selmar
Copy link

Selmar commented Mar 31, 2024

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;
	}
}
@Selmar
Copy link
Author

Selmar commented Apr 7, 2024

It works fine in a separate project. Surely something related to Unity and perhaps out of the scope of this project?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant