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".

@som-snytt som-snytt force-pushed the issue/21187-contextual-func-lit branch from 4684bed to f1d5ced Compare September 2, 2025 18:01
Copy link
Member

@noti0na1 noti0na1 left a comment

Choose a reason for hiding this comment

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

LGTM

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, just two minor nitpicks

@@ -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, "Wwrong-arrow", "Warn if function arrow was used instead of context literal ?=>.")
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, "Wwrong-arrow", "Warn if function arrow was used instead of context literal ?=>.")
private val WwrongArrow = BooleanSetting(WarningSetting, "Wwrong-arrow", "Warn if function arrow was used instead of context literal ?=>.")

@@ -311,6 +312,7 @@ private sealed trait WarningSettings:
def unstableInlineAccessors(using Context): Boolean = allOr(WunstableInlineAccessors)
def toStringInterpolated(using Context): Boolean = allOr(WtoStringInterpolated)
def recurseWithDefault(using Context): Boolean = allOr(WrecurseWithDefault)
def dubiousContextual(using Context): Boolean = allOr(WdubiousContextual)
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
def dubiousContextual(using Context): Boolean = allOr(WdubiousContextual)
def wrongArrow(using Context): Boolean = allOr(WdubiousContextual)

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