Skip to content

Scala: public canonical ctors for S.TuplePattern and S.FunctionCall#7462

Merged
knutwannheden merged 1 commit intomainfrom
public-canonical-ctors-for-scala-ast-types
Apr 23, 2026
Merged

Scala: public canonical ctors for S.TuplePattern and S.FunctionCall#7462
knutwannheden merged 1 commit intomainfrom
public-canonical-ctors-for-scala-ast-types

Conversation

@knutwannheden
Copy link
Copy Markdown
Contributor

@knutwannheden knutwannheden commented Apr 23, 2026

Motivation

S.TuplePattern and S.FunctionCall previously exposed only a private @AllArgsConstructor-generated canonical constructor whose first parameter is the padding WeakReference.

Summary

  • Added @RequiredArgsConstructor to S.TuplePattern and S.FunctionCall, alongside the existing @AllArgsConstructor(access = AccessLevel.PRIVATE).
  • Because the padding field is @NonFinal, @RequiredArgsConstructor excludes it — generating a public canonical constructor that omits the WeakReference, exactly matching the pattern used by S.CompilationUnit in the same file and by rewrite-java types such as J.MethodInvocation.
  • The private padding-aware constructor is retained for internal use.
  • Audited the rest of the org.openrewrite.scala.tree.* package: the remaining 6 final tree classes (CompilationUnit, Wildcard, StatementExpression, TypeAscription, TypeAlias, PatternDefinition) already have a public canonical constructor — either via @RequiredArgsConstructor or hand-written — so no further changes are needed.

Test plan

  • ./gradlew :rewrite-scala:compileJava succeeds.

…and `S.FunctionCall`

Both classes previously exposed only a private `@AllArgsConstructor`-generated
canonical constructor whose first parameter is the padding `WeakReference`.
Deserializers (such as moderne-ast-write's V3 codegen) skip non-public
constructors and constructors that take a `WeakReference`, so these types
were invisible to static codegen and fell through to the dynamic-schema
read path — where, lacking any other public constructor, construction
failed and source files were substituted with a `Quark` + `DeserializationError`
marker.

Adding `@RequiredArgsConstructor` generates a public canonical constructor
that excludes the `@NonFinal` padding field, matching the pattern already
used by `S.CompilationUnit` and by rewrite-java types such as `J.MethodInvocation`.
The private padding-aware constructor remains for internal use.
@github-project-automation github-project-automation Bot moved this to In Progress in OpenRewrite Apr 23, 2026
@knutwannheden knutwannheden changed the title rewrite-scala: public canonical ctors for S.TuplePattern and S.FunctionCall Scala: public canonical ctors for S.TuplePattern and S.FunctionCall Apr 23, 2026
@knutwannheden knutwannheden merged commit 46d442e into main Apr 23, 2026
1 check passed
@knutwannheden knutwannheden deleted the public-canonical-ctors-for-scala-ast-types branch April 23, 2026 09:45
@github-project-automation github-project-automation Bot moved this from In Progress to Done in OpenRewrite Apr 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

1 participant