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

Add support for @deprecatedInheritance #19082

Merged
merged 1 commit into from
Dec 20, 2023
Merged

Conversation

hamzaremmal
Copy link
Member

Closes #19002

@hamzaremmal
Copy link
Member Author

scala3-bootstrapped is compiled with -Xfatal-warnings. The errors are initially warnings.

@hamzaremmal hamzaremmal marked this pull request as ready for review November 26, 2023 15:57
Copy link
Contributor

@som-snytt som-snytt left a comment

Choose a reason for hiding this comment

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

I recognize the anon map rewrite from scala 2.
Not sure if my other comments are helpful yet.


(ctx.owner.is(Synthetic) && sym.is(CaseClass))
|| ctx.owner.ownersIterator.exists(if sym.isEnumCase then isDeprecatedOrEnum else _.isDeprecated)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I see you are adding braces just for methods. You might prefer end SkipWarning.

if !skipWarning(psym) then
val msg = annot.argumentConstantString(0).map(msg => s": $msg").getOrElse("")
val since = annot.argumentConstantString(1).map(version => s" (since: $version)").getOrElse("")
report.deprecationWarning(em"inheritance from $psym is deprecated$since$msg", pos)
Copy link
Contributor

Choose a reason for hiding this comment

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

IIRC filtering on empty annot arg avoids deprecated (since: ) which is minor but looks funny. I think because they starting warning (years ago) if you omitted the since arg, you'd see deprecated("no way", "").

Copy link
Member Author

Choose a reason for hiding this comment

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

This is already the case, see tests/warn/i19002.check

@nicolasstucki nicolasstucki added the release-notes Should be mentioned in the release notes label Dec 8, 2023
for parent <- parents
psym = parent.tpe.classSymbol
if !skipWarning(psym)
annot <- psym.getAnnotation(defn.DeprecatedInheritanceAnnot)
Copy link
Contributor

Choose a reason for hiding this comment

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

It's cheaper to check the annotation than to walk owners checking whether to skipWarning, also the annotation is rare, so it's more natural to reverse the lines. It's a matter of style (?) whether to have trailing if in the for comprehension or move it to the body.

Copy link
Member Author

Choose a reason for hiding this comment

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

I've actually put the if after but I agree, I will switch them

annot <- psym.getAnnotation(defn.DeprecatedInheritanceAnnot)
do
val msg = annot.argumentConstantString(0).map(msg => s": $msg").getOrElse("")
val since = annot.argumentConstantString(1).map(version => s" (since: $version)").getOrElse("")
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
val since = annot.argumentConstantString(1).map(version => s" (since: $version)").getOrElse("")
val since = annot.argumentConstantString(1).filter(!_.isEmpty).map(version => s" (since: $version)").getOrElse("")

Copy link
Member Author

Choose a reason for hiding this comment

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

There is no need for the filter (See : tests/warn/i19002.check)

Copy link
Contributor

Choose a reason for hiding this comment

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

In that case, I don't know what dotty is doing with the annotation. It has a default arg that is empty string. I won't press the matter here, but I wonder what happens to the string. In scala 2, we must handle the empty string to avoid (since: ) text. Sorry I don't already know the answer, I'll check it out later.

Copy link
Member Author

Choose a reason for hiding this comment

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

It has a default arg that is empty string. I won't press the matter here, but I wonder what happens to the string.

We don't transform annotations in Dotty, therefore, it does not have the knowledge of the default parameter in case we are using named arguments. The only way to have the message (since: ) is to explicitly write @deprecatedInheritance(since = "").

@hamzaremmal hamzaremmal merged commit 3e96130 into scala:main Dec 20, 2023
19 checks passed
@som-snytt som-snytt assigned nicolasstucki and unassigned som-snytt Dec 20, 2023
@hamzaremmal hamzaremmal deleted the i19002 branch December 21, 2023 12:13
@Kordyjan Kordyjan added this to the 3.4.1 milestone Feb 14, 2024
WojciechMazur added a commit that referenced this pull request Jun 26, 2024
Backports #19082 to the LTS branch.

PR submitted by the release tooling.
[skip ci]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release-notes Should be mentioned in the release notes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Missing deprecatedInheritance warnings
4 participants