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

[NotClientImplementable] does not prevent builds #15736

Open
colejohnson66 opened this issue May 15, 2024 · 8 comments
Open

[NotClientImplementable] does not prevent builds #15736

colejohnson66 opened this issue May 15, 2024 · 8 comments
Labels
area-infrastructure Issues related to CI/tooling infrastructur bug

Comments

@colejohnson66
Copy link

colejohnson66 commented May 15, 2024

Describe the bug

Avalonia tags interfaces with [NotClientImplementable] to prevent downstream users from deriving their own classes. This produces an error in Rider, but not during builds.

To Reproduce

Add the following class:

public class MyCustomPen : IPen
{
    public IBrush? Brush { get; }
    public IDashStyle? DashStyle { get; }
    public PenLineCap LineCap { get; }
    public PenLineJoin LineJoin { get; }
    public double MiterLimit { get; }
    public double Thickness { get; }
}

Expected behavior

A compiler error. Instead, it compiles fine despite the error in Rider.

Avalonia version

11.0.10

OS

No response

Additional context

The IL rewriter only patches up the "ref" assemblies. This causes errors in tools using them, but not during builds that use the normal assemblies.

Using dotPeek, I can confirm that internal void (This interface or abstract class is -not- implementable by user code !)(); only exists in the "ref" assemblies, but is missing from the "lib" ones.

~/.nuget/avalonia/11.0.10/lib/net6.0/Avalonia.Base.dll

image

~/.nuget/avalonia/11.0.10/ref/net6.0/Avalonia.Base.dll

image

My Implementation

image

@maxkatz6
Copy link
Member

That's mostly by design, as we wanted to keep non-ref assemblies with no changes. Making it possible to access private APIs if needed (for example, if somebody writes a custom backend).

But that's not ideal situation. Yes.

Alternative idea was to use C# analyzers, which would work better in this scenario. But won't support F# or other non-C# languages.

@maxkatz6 maxkatz6 added the area-infrastructure Issues related to CI/tooling infrastructur label May 16, 2024
@robloo
Copy link
Contributor

robloo commented May 16, 2024

Personally, I think it's best to allow this usage. It's a good middle road: you get the warning telling you not to use the API. If you need it or know better you can override.

@colejohnson66
Copy link
Author

I would be fine with that as well, but I'd expect an analyzer warning I can silence. With the current setup, Rider shows an error that I can't get rid of.

@maxkatz6
Copy link
Member

With the current setup, Rider shows an error

As it should.

that I can't get rid of.

<AvaloniaAccessUnstablePrivateApis>true</AvaloniaAccessUnstablePrivateApis>

@colejohnson66
Copy link
Author

colejohnson66 commented May 17, 2024

I think my gripe is that it's an error, not a warning. Yet, it still behaves like a warning. I'm fine with Rider flagging usage, but not in a way that abuses ref assemblies.

For example, for #8266, I was told to try reimplementing LinearGradientBrush myself with some changes to test a potential fix. However, the error in Rider led me to believe that I couldn't, so I didn't even try. If it was instead a warning about an "unstable" interface, I could've just ignored it to try.

Also, that property is not documented anywhere on the website.

@maxkatz6
Copy link
Member

Also, that property is not documented anywhere on the website.

Correct. We don't want users to rely on this property, as these APIs are unstable and can break in minor releases. Still, this option exists.

@kekekeks
Copy link
Member

This is rather interesting. Previously Roslyn was using reference assemblies for compilation and the build would fail.
Perhaps something got changed in .NET SDK?

@kekekeks
Copy link
Member

kekekeks commented May 18, 2024

Actually, CoreCompile is being fed with 11.0.0/ref/net6.0/Avalonia.dll, not sure why compiler ignores the internal interface member there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-infrastructure Issues related to CI/tooling infrastructur bug
Projects
None yet
Development

No branches or pull requests

4 participants