Skip to content

Allow appliedToTypeTrees to operate on block expressions#26259

Open
SolalPirelli wants to merge 1 commit into
scala:mainfrom
dotty-staging:solal/26238
Open

Allow appliedToTypeTrees to operate on block expressions#26259
SolalPirelli wants to merge 1 commit into
scala:mainfrom
dotty-staging:solal/26238

Conversation

@SolalPirelli

Copy link
Copy Markdown
Contributor

Fixes #26238

See the -min test for an explanation of what's going on

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

Not at all

How was the solution tested?

New automated tests (including the issue's reproducer, if applicable)

@SolalPirelli SolalPirelli requested a review from sjrd June 8, 2026 11:16
Comment thread tests/pos/26238.scala
object toplevel {

@deprecated("pls work this out")
def ??? = scala.Predef.`???`

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can we at least remove dead code from the non-minimized test?

if targs.isEmpty then tree else TypeApply(tree, targs)
if targs.isEmpty then tree else tree match
case Block(stmts, expr) if stmts.nonEmpty => Block(stmts, TypeApply(expr, targs))
case _ => TypeApply(tree, targs)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This fix is suspicious. What if it's an If where the two branches need a type application? What is it about Blocks that deserves a special-case here, but not other constructs? Also why do this for type arguments but not term arguments?

If there is a specific call site that for some reason creates a Block, then that call site is probably the correct place to take care of it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I agree it's not an amazing fix, but the bit where a Block is created seems quite far from this, and I don't see a way to not create a Block there given the need for a temp local to use the argument twice (once as an arg, once as an arg of the default value function of the using)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'm not saying the call site should not create a Block. But when it creates a Block, it should make sure to push any type application inside the block itself.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The Block is created in typedUnadapted, and this method here is called in adapt, both from the bit of typed that does adapt(typedUnadapted(...), ...).

I agree in principle we shouldn't have to add a special case here but I don't see how to avoid it without changing a lot of logic.

@SolalPirelli SolalPirelli marked this pull request as ready for review June 9, 2026 13:56
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.

crash interaction between extension def, default args, and path-dependent typing

2 participants