Scala parser: add try/catch/finally, match, and fix complex parameter types#7260
Merged
jkschneider merged 1 commit intomainfrom Apr 2, 2026
Merged
Scala parser: add try/catch/finally, match, and fix complex parameter types#7260jkschneider merged 1 commit intomainfrom
jkschneider merged 1 commit intomainfrom
Conversation
- Map Trees.Try to J.Try with J.Try.Catch for each case clause - Map Trees.Match to J.Switch with J.Case for each pattern - Add ScalaPrinter overrides for try/catch (Scala syntax), switch/case (match syntax) - Fix modifier spacing before def keyword (implicit def, abstract override def) - Handle Statement types (e.g., match) in method body wrapping - All 8 TryTest cases pass - 1 remaining match printer formatting issue (throwInMatchCase)
jkschneider
added a commit
that referenced
this pull request
Apr 2, 2026
…e while fallback - Parameterless methods (def name: Type) now map to J.MethodDeclaration with OmitBraces marker on empty param container — printer omits () - Annotated methods (@deprecated def ...) now map to J.MethodDeclaration with annotations extracted and def-modifier carrying annotation-to-def spacing - Remove while loop fallback — while loops in method bodies handled by parser - Remove AppliedTypeTree fallback (already fixed in #7260) - 3 remaining fallbacks: procedure syntax, nested braces, function type params - 5 test failures: 3 complex annotations (with args), 2 while body block whitespace
jkschneider
added a commit
that referenced
this pull request
Apr 2, 2026
…e while fallback - Parameterless methods (def name: Type) now map to J.MethodDeclaration with OmitBraces marker on empty param container — printer omits () - Annotated methods (@deprecated def ...) now map to J.MethodDeclaration with annotations extracted and def-modifier carrying annotation-to-def spacing - Remove while loop fallback — while loops in method bodies handled by parser - Remove AppliedTypeTree fallback (already fixed in #7260) - 3 remaining fallbacks: procedure syntax, nested braces, function type params - 5 test failures: 3 complex annotations (with args), 2 while body block whitespace
jkschneider
added a commit
that referenced
this pull request
Apr 2, 2026
…e while fallback - Parameterless methods (def name: Type) now map to J.MethodDeclaration with OmitBraces marker on empty param container — printer omits () - Annotated methods (@deprecated def ...) now map to J.MethodDeclaration with annotations extracted and def-modifier carrying annotation-to-def spacing - Remove while loop fallback — while loops in method bodies handled by parser - Remove AppliedTypeTree fallback (already fixed in #7260) - 3 remaining fallbacks: procedure syntax, nested braces, function type params - 5 test failures: 3 complex annotations (with args), 2 while body block whitespace
jkschneider
added a commit
that referenced
this pull request
Apr 2, 2026
…e while fallback - Parameterless methods (def name: Type) now map to J.MethodDeclaration with OmitBraces marker on empty param container — printer omits () - Annotated methods (@deprecated def ...) now map to J.MethodDeclaration with annotations extracted and def-modifier carrying annotation-to-def spacing - Remove while loop fallback — while loops in method bodies handled by parser - Remove AppliedTypeTree fallback (already fixed in #7260) - 3 remaining fallbacks: procedure syntax, nested braces, function type params - 5 test failures: 3 complex annotations (with args), 2 while body block whitespace
jkschneider
added a commit
that referenced
this pull request
Apr 2, 2026
…e while fallback - Parameterless methods (def name: Type) now map to J.MethodDeclaration with OmitBraces marker on empty param container — printer omits () - Annotated methods (@deprecated def ...) now map to J.MethodDeclaration with annotations extracted and def-modifier carrying annotation-to-def spacing - Remove while loop fallback — while loops in method bodies handled by parser - Remove AppliedTypeTree fallback (already fixed in #7260) - 3 remaining fallbacks: procedure syntax, nested braces, function type params - 5 test failures: 3 complex annotations (with args), 2 while body block whitespace
jkschneider
added a commit
that referenced
this pull request
Apr 2, 2026
…e while fallback - Parameterless methods (def name: Type) now map to J.MethodDeclaration with OmitBraces marker on empty param container — printer omits () - Annotated methods (@deprecated def ...) now map to J.MethodDeclaration with annotations extracted and def-modifier carrying annotation-to-def spacing - Remove while loop fallback — while loops in method bodies handled by parser - Remove AppliedTypeTree fallback (already fixed in #7260) - 3 remaining fallbacks: procedure syntax, nested braces, function type params - 5 test failures: 3 complex annotations (with args), 2 while body block whitespace
timtebeek
added a commit
that referenced
this pull request
Apr 6, 2026
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.
2 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Trees.Try→J.TrywithJ.Try.Catchfor eachcaseclauseTrees.Match→J.SwitchwithJ.Casefor each pattern caseScalaPrinteroverrides for Scala-style try/catch and match syntaxMap[String, Any],Array[String], etc.) — no longer fall back toJ.UnknowndefkeywordStatementtypes in method body wrappingextractSourcecursor issue invisitMethodParameterTest plan