Skip to content

Commit

Permalink
Convert j to expression in visitPostfixExpression
Browse files Browse the repository at this point in the history
  • Loading branch information
traceyyoshima committed Nov 15, 2023
1 parent 7f8edbf commit 5b7a8dd
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2731,7 +2731,7 @@ public J visitPostfixExpression(KtPostfixExpression expression, ExecutionContext
} else if (type instanceof JavaType.Variable) {
type = ((JavaType.Variable) type).getType();
}
J j = requireNonNull(expression.getBaseExpression()).accept(this, data);
J j = convertToExpression(requireNonNull(expression.getBaseExpression()).accept(this, data));
IElementType referencedNameElementType = expression.getOperationReference().getReferencedNameElementType();
if (referencedNameElementType == KtTokens.EXCLEXCL) {
// j = j.withMarkers(j.getMarkers().addIfAbsent(new CheckNotNull(randomId(), prefix(expression.getOperationReference()))));
Expand Down
32 changes: 32 additions & 0 deletions src/test/java/org/openrewrite/kotlin/tree/IfTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -173,4 +173,36 @@ fun foo(choices: List<Pair<String, String>>, peekedHeader: Regex) {
)
);
}

@Issue("https://github.com/openrewrite/rewrite-kotlin/issues/390")
@Test
void typeParameter() {
rewriteRun(
kotlin(
"""
val enabled = true
fun foo(arg: String = if (enabled) "foo" else "bar"): String {
return arg
}
"""
)
);
}

@Issue("https://github.com/openrewrite/rewrite-kotlin/issues/392")
@Test
void postfixExpression() {
rewriteRun(
kotlin(
"""
fun foo(arg: Boolean): String? {
return if (arg) "" else null
}
fun bar(arg: Boolean) {
if (arg) { foo(true) } else { foo(false) }!!
}
"""
)
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -366,21 +366,6 @@ fun method2() {
);
}

@Issue("https://github.com/openrewrite/rewrite-kotlin/issues/390")
@Test
void ifExpression() {
rewriteRun(
kotlin(
"""
val enabled = true
fun foo(arg: String = if (enabled) "foo" else "bar"): String {
return arg
}
"""
)
);
}

@Test
void argumentTrailingComma() {
rewriteRun(
Expand Down

0 comments on commit 5b7a8dd

Please sign in to comment.