Skip to content

Iterate where: explanations to fixed point#25851

Open
mbovel wants to merge 2 commits intoscala:mainfrom
mbovel:mb/where-clause-fixpoint
Open

Iterate where: explanations to fixed point#25851
mbovel wants to merge 2 commits intoscala:mainfrom
mbovel:mb/where-clause-fixpoint

Conversation

@mbovel
Copy link
Copy Markdown
Member

@mbovel mbovel commented Apr 17, 2026

When a recorded type's explanation in the where: clause mentions another recorded type that also needs explanation, the latter is silently dropped. This happens because explanations collects the entries to explain once, up front, and then renders each one; rendering an explanation for entry X may call ParamRefNameString (or similar) on entries nested inside X's bounds, which adds them to seen — but too late for the pass that produced the final output.

Concretely, for

trait Ord[T]
trait Op[A, V]
object Op:
  given Op[Int, Int] = new Op[Int, Int] {}

def min[A, V, W <: Ord[V]](x: A)(implicit op: Op[A, V], w: W): W = w
def foo(x: Double) = ???
def test = foo(min(3)) // error

we used to get:

where:    W is a type variable with constraint <: Ord[V] & Double

with no explanation for V. After this change:

where:    W is a type variable with constraint <: Ord[V] & Double
          V is a type variable

The fix is to iterate the explanation loop to a fixed point: as long as rendering an explanation causes a new entry to be recorded, collect and explain it in the next round. This also surfaces a number of previously missing explanations in capture-checking error messages (nested , anonymous-function parameters, etc.), which account for the bulk of the checkfile updates.

How much have you relied on LLM-based tools in this contribution?

Extensively, for everything.

How was the solution tested?

One new test showing the change, plus existing checkfiles updates.

mbovel added 2 commits April 17, 2026 17:14
Rendering an explanation for a recorded type may itself record new
entries (e.g. a type variable's constraint mentioning another type
variable). Collect explanations in a loop so every referenced entry
appears in the where clause.
@mbovel mbovel changed the title Mb/where clause fixpoint Iterate where: explanations to fixed point Apr 17, 2026
@mbovel mbovel marked this pull request as ready for review April 17, 2026 18:26
@mbovel mbovel requested a review from natsukagami April 17, 2026 18:26
@mbovel
Copy link
Copy Markdown
Member Author

mbovel commented Apr 17, 2026

Assigning you @natsukagami because GitHub suggested so. Would you agree to review? 🙂

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.

1 participant