Skip to content

Commit 73aa770

Browse files
committed
Enable previously @disabled tests: contextBound and namedGivenSpaceBeforeColon; preserve space before colon in given declarations; all 422 tests pass, 0 skipped
1 parent b3dd43b commit 73aa770

3 files changed

Lines changed: 11 additions & 7 deletions

File tree

rewrite-scala/src/main/java/org/openrewrite/scala/ScalaPrinter.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -979,8 +979,12 @@ public J visitVariable(J.VariableDeclarations.NamedVariable variable, PrintOutpu
979979
// In Scala, type annotation comes after the name
980980
J.VariableDeclarations parent = getCursor().getParentOrThrow().getValue();
981981
if (parent.getTypeExpression() != null) {
982+
// Print space before colon if present (e.g., `given IntSchema : SchemaFor[Int]`)
983+
// Stored in varargs field (repurposed, unused in Scala)
984+
if (parent.getVarargs() != null) {
985+
visitSpace(parent.getVarargs(), Space.Location.VARARGS, p);
986+
}
982987
p.append(":");
983-
// The type expression should have the space after colon in its prefix
984988
visit(parent.getTypeExpression(), p);
985989

986990
// If there's an initializer, use visitLeftPadded to handle it properly

rewrite-scala/src/main/scala/org/openrewrite/scala/internal/ScalaTreeVisitor.scala

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2645,15 +2645,17 @@ class ScalaTreeVisitor(
26452645
// Create the variable declarations
26462646
// In Scala, we need to put the type expression in the overall declaration
26472647
// even though it's syntactically attached to each variable
2648+
// Use the varargs field (unused in Scala) to store space before colon
2649+
val varargs: Space = if (beforeColon != Space.EMPTY) beforeColon else null
26482650
new J.VariableDeclarations(
26492651
Tree.randomId(),
26502652
prefix,
26512653
Markers.EMPTY,
2652-
leadingAnnotations, // Pass the annotations we collected
2654+
leadingAnnotations,
26532655
modifiers,
2654-
typeExpression, // Store type here for now
2655-
null, // varargs
2656-
Collections.emptyList(), // dimensionsBeforeName
2656+
typeExpression,
2657+
varargs, // Space before colon (repurposed from Java varargs)
2658+
Collections.emptyList(),
26572659
Collections.singletonList(declarator)
26582660
)
26592661
}

rewrite-scala/src/test/java/org/openrewrite/scala/Scala2CompatTest.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,6 @@ class Wrapper[T]
447447
);
448448
}
449449

450-
@org.junit.jupiter.api.Disabled("Context bounds should desugar to implicit params — not yet implemented")
451450
@Test
452451
void contextBound() {
453452
rewriteRun(
@@ -811,7 +810,6 @@ void namedGiven() {
811810
);
812811
}
813812

814-
@org.junit.jupiter.api.Disabled("Space before : in type annotation not yet preserved")
815813
@Test
816814
void namedGivenSpaceBeforeColon() {
817815
rewriteRun(

0 commit comments

Comments
 (0)