Skip to content

Handle untpd.ParsedTry in Scala 3 parser#7285

Draft
timtebeek wants to merge 1 commit intomainfrom
tim/handle-parsed-try
Draft

Handle untpd.ParsedTry in Scala 3 parser#7285
timtebeek wants to merge 1 commit intomainfrom
tim/handle-parsed-try

Conversation

@timtebeek
Copy link
Copy Markdown
Member

Summary

  • Handle untpd.ParsedTry AST nodes in ScalaTreeVisitor, which were falling through to visitUnknown and producing J.Unknown instead of J.Try
  • The Scala 3 compiler uses two representations for try/catch/finally: Trees.Try (typed) and untpd.ParsedTry (untyped). PR Scala parser: add try/catch/finally, match, and fix complex parameter types #7260 handled Trees.Try but ParsedTry extends Trees.Tree directly, not Trees.Try, so it was missed
  • Update ScalaPrinter to use AST-stored spacing for catch block formatting instead of hardcoded whitespace

Test plan

  • Added ParsedTryTest with cases for try/finally with throw and try/catch with Throwable (patterns that produce ParsedTry)
  • Verify downstream recipe tests pass (AvoidThrowInFinally, NarrowCatchClause, UseNonFatalMatcher in moderneinc/recipes-scala)

The Scala 3 compiler uses two different AST representations for
try/catch/finally: `Trees.Try` (typed/desugared) and `untpd.ParsedTry`
(untyped/parsed). PR #7260 added handling for `Trees.Try` but
`ParsedTry` was falling through to `visitUnknown` since it extends
`Trees.Tree` directly and not `Trees.Try`.

Add `visitParsedTry`/`visitParsedTryImpl` to handle `ParsedTry` by
extracting cases from its `handler` (a `Match` tree) and mapping them
to `J.Try` AST nodes. Update `ScalaPrinter` to use AST-stored spacing
for catch block formatting.
@greg-at-moderne
Copy link
Copy Markdown
Contributor

and untpd.ParsedTry (untyped)

IMHO this might be some effect of some classpath lacking or similar. And therefore Scala Compiler failing to provide type attribution properly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: In Progress

Development

Successfully merging this pull request may close these issues.

2 participants