Skip to content

Conversation

@jpobst
Copy link
Contributor

@jpobst jpobst commented Aug 11, 2022

Traditionally generator was inconsistent with the style in which it generated [Obsolete] attributes, such as:

[Obsolete]
[Obsolete ("")]
[Obsolete (@"")]
[ObsoleteAttribute]
[global::System.Obsolete]

We wrote a temporary compatibility layer to preserve these differences when we refactored generator. This allowed us to do a source code level text compare against a large corpus of generated code (Mono.Android/AndroidX/GPS) to ensure there were no changes.

Now that we are passed this phase, we can remove these hacks and standardize on [global::System.Obsolete] and [global::System.Obsolete (@"message")].

XA test build to ensure there were no actual changes via ApiCompat testing: dotnet/android#7253.

@jpobst jpobst marked this pull request as ready for review August 12, 2022 13:39

writer.WriteLine (")]");
if (content.HasValue ())
writer.WriteLine ($"[global::System.Obsolete ({content})]");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A concern with this approach is that it could result in invalid code: if Message is null and IsError is true, then we would attempt to emit [Obsolete(error:true)], which will fail to compile as there is no Obsolete(bool) constructor.

Is it possible for Message to be null and IsError to be true?

One one level, "no", because @deprecated is "never" null.

Except when we only pass null:

% git grep 'SourceWriterExtensions.AddObsolete.*null'    
tools/generator/SourceWriters/MethodCallback.cs:                        SourceWriterExtensions.AddObsolete (Attributes, null, forceDeprecate: !string.IsNullOrWhiteSpace (method.Deprecated));
tools/generator/SourceWriters/MethodCallback.cs:                        SourceWriterExtensions.AddObsolete (Attributes, null, forceDeprecate: !string.IsNullOrWhiteSpace (method.Deprecated))

These callsites don't use isError:true, so we should be fine.

@jonpryor jonpryor merged commit 6d1ae4e into main Aug 12, 2022
@jonpryor jonpryor deleted the standardize-obsolete branch August 12, 2022 14:47
@github-actions github-actions bot locked and limited conversation to collaborators Apr 12, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants