Skip to content

Conversation

som-snytt
Copy link
Contributor

Fixes #21187

If a function literal x => body has an expected type X ?=> ? then maybe they intended to write x ?=> body.

As shown in the test, maybe types will misalign in other ways to emit warnings.

@som-snytt som-snytt marked this pull request as ready for review September 2, 2025 04:29
@Gedochao Gedochao requested review from tgodzik and noti0na1 September 2, 2025 05:32
@@ -168,6 +168,7 @@ private sealed trait WarningSettings:
private val WunstableInlineAccessors = BooleanSetting(WarningSetting, "WunstableInlineAccessors", "Warn an inline methods has references to non-stable binary APIs.")
private val WtoStringInterpolated = BooleanSetting(WarningSetting, "Wtostring-interpolated", "Warn a standard interpolator used toString on a reference type.")
private val WrecurseWithDefault = BooleanSetting(WarningSetting, "Wrecurse-with-default", "Warn when a method calls itself with a default argument.")
private val WdubiousContextual = BooleanSetting(WarningSetting, "Wdubious-contextual", "Warn about T ?=> (t: T) => U.")
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
private val WdubiousContextual = BooleanSetting(WarningSetting, "Wdubious-contextual", "Warn about T ?=> (t: T) => U.")
private val WunlikelyContextual = BooleanSetting(WarningSetting, "Wunlikely-contextual", "Warn about T ?=> (t: T) => U. when a normal function literal was used instead of context one."),

just because the word is prone to typos for non english speakers and a bit more explanation aside from signature?

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 rely on -Xlint or now -Wall. Though I do like the word "dubious". All warnings are dubious because they begin with -W or "dubya".

object Zone:
inline def apply[T](inline f: Zone ?=> T): T = f(using new Zone)

inline def zone[A](inline f: Zone ?=> A) = Zone.apply(z => f(using z)) // warn suspicious contextualizing
Copy link
Contributor

Choose a reason for hiding this comment

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

Will this be reported with:

def zone[A](f: Zone ?=> A) = Zone.apply(z => f(using z))

as well? Maybe the warning should only be for the inline cases, where it might cause most issues.

What do you think?

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 think it's the same issue, which is that the function literal is wrapped in a context function. I added it to the test to document the behavior is the same.

@som-snytt som-snytt force-pushed the issue/21187-contextual-func-lit branch from 4684bed to f1d5ced Compare September 2, 2025 18:01
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.

Exceptions inexplicably swallowed when inlined context functions interact
3 participants