Skip to content

Gradual warning for deprecated nonlocal return #15303

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

Merged
merged 2 commits into from
May 30, 2022

Conversation

som-snytt
Copy link
Contributor

@som-snytt som-snytt commented May 27, 2022

Follow up #15298

warns for nonlocal returns from -source:3.2
It's still true that it errors only on -source:future.

@som-snytt som-snytt marked this pull request as ready for review May 28, 2022 02:02
@som-snytt
Copy link
Contributor Author

I would have preferred a test for the warning and also for the printer.

"Non local returns are no longer supported; use scala.util.control.NonLocalReturns instead",
tree.srcPos,
from = future)
warnFrom = `3.0`,
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
warnFrom = `3.0`,
warnFrom = `3.2`,

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It used to warn if you weren't in a "Scala 2" mode or frame of mind. That is 3.0-migration now? But I see that this warns under 3.0-migration. I expected X-migration semantics: "error or migration warning", and "warning or free pass if migrating at X".

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Pushed that conjecture.

@som-snytt som-snytt marked this pull request as draft May 29, 2022 06:31
@@ -74,7 +74,7 @@ object report:

def gradualErrorOrMigrationWarning(msg: Message, pos: SrcPos = NoSourcePosition, warnFrom: SourceVersion, errorFrom: SourceVersion)(using Context): Unit =
if sourceVersion.isAtLeast(errorFrom) then errorOrMigrationWarning(msg, pos, errorFrom)
else if sourceVersion.isAtLeast(warnFrom) then warning(msg, pos)
else if sourceVersion.ordinal >= warnFrom.ordinal then warning(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.

As an example, this change would disable the new refutable pattern binding warnings under -source 3.2-migration (but the offending code is rewritten under -rewrite -source 3.2-migration). Is that the desired behavior?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I saw that usage but hadn't quite decoded it yet, so the behavior is not desired in particular. At least the PR is in draft mode.

At a glance, I may have intended it. Mostly because there is no Scala 2 mode for the current use case. Maybe that is a red herring and there is no exclusion (for nonlocal return if I'm migrating from Scala 2) or as suggested just defer it to 3.2.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Or I read too much into -migration or misread it. It means don't error yet, just warn me migratorily. Then gradual means warn even before that, so does -migration mean anything? Is it just for when rewrites kick in? As in, "help me migrate".

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The only I resisted the suggestion to warn at 3.2 was that I thought I read that there is a use case for keeping source at 3.0. I don't remember the use case around library compatibility. Anyone doing that would miss out on this niche case warning.

Copy link
Member

Choose a reason for hiding this comment

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

so I tried to compile a file that has a non-local return with 3.0.0 and there was no warning or anything, so I think compiling with 3.2.0 but using -source:3.0 should still not make a warning. Regardless you made the change I requested :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, deprecation was in 0.16, errorOrMigration at 3.1 in 0.24 for -migration scheme, and at future in 3.0.0-RC1. The docs make plain the feature is deprecated rather than dropped outright, but introducing the warning in 3.2 is sufficiently effective.

@som-snytt som-snytt force-pushed the tweak/warn-nonlocal-return branch from 82fb399 to 5f833b3 Compare May 29, 2022 17:44
@som-snytt som-snytt marked this pull request as ready for review May 29, 2022 17:50
@som-snytt
Copy link
Contributor Author

Back-tweaked to warn from 3.2 as suggested, and dropped the tweak not to warn at x-migration.

@bishabosha bishabosha added this to the 3.2.0-RC1 milestone May 30, 2022
@bishabosha
Copy link
Member

@odersky does this need SIP approval?

@odersky
Copy link
Contributor

odersky commented May 30, 2022

@bishabosha No I think that was already approved in the last batch.

@odersky odersky merged commit d522766 into scala:main May 30, 2022
@som-snytt som-snytt deleted the tweak/warn-nonlocal-return branch May 30, 2022 17:25
@bishabosha bishabosha added the release-notes Should be mentioned in the release notes label Jun 1, 2022
@Kordyjan Kordyjan modified the milestones: 3.2.0-RC1, 3.2.0 Aug 2, 2023
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.

5 participants