Skip to content

Warn trivial recursion with module prefix #23278

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 1 commit into from
Jun 3, 2025

Conversation

som-snytt
Copy link
Contributor

Fixes #23277

First, loosen the test for whether to warn for module.recur(). The this assignment has a RHS that is not pure (because of module init) but isStable (and not significant with respect to the warning).

Second, avoid emitting such a this assignment if the prefix is the enclosing module. The existing code checks for a prefix that is Enclosing.this.

Other "aliasing" prefixes are not considered, such as a method with result this.type, since they could execute arbitrary intended effects.

@som-snytt
Copy link
Contributor Author

som-snytt commented May 28, 2025

As pointed out on the ticket,

def apply(i: Int, s: String): Two = Two(i, s) // warn because unprefixed Two is deemed pure

Also pondering rhs.tpe.isStable vs tpd.isIdempotentPath(rhs). Also whether to revert that change if the second fix is accepted, since I can't trick it into using that code path.

@som-snytt som-snytt force-pushed the issue/23277-this-recur branch from 5ab3c16 to 3ed8fb3 Compare May 31, 2025 20:19
@som-snytt som-snytt marked this pull request as ready for review May 31, 2025 20:20
@Gedochao Gedochao requested a review from tgodzik June 2, 2025 06:16
Copy link
Contributor

@tgodzik tgodzik left a comment

Choose a reason for hiding this comment

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

LGTM!

@tgodzik tgodzik merged commit 451cc74 into scala:main Jun 3, 2025
29 checks passed
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

Successfully merging this pull request may close these issues.

Missing warning for Infinite recursive call in object
2 participants