Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed ConeTypeProjection error #335

Merged
merged 1 commit into from
Oct 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import org.jetbrains.kotlin.fir.java.declarations.FirJavaField
import org.jetbrains.kotlin.fir.java.declarations.FirJavaMethod
import org.jetbrains.kotlin.fir.java.declarations.FirJavaValueParameter
import org.jetbrains.kotlin.fir.references.FirResolvedNamedReference
import org.jetbrains.kotlin.fir.resolve.inference.ConeTypeParameterBasedTypeVariable
import org.jetbrains.kotlin.fir.resolve.toFirRegularClass
import org.jetbrains.kotlin.fir.resolve.toFirRegularClassSymbol
import org.jetbrains.kotlin.fir.resolve.toSymbol
Expand Down Expand Up @@ -189,6 +190,14 @@ class KotlinTypeSignatureBuilder(private val firSession: FirSession) : JavaTypeS
is FirOuterClassTypeParameterRef -> {
return signature(type.symbol)
}

is ConeTypeVariable -> {
when (type) {
is ConeTypeParameterBasedTypeVariable -> {
return signature(type.typeParameterSymbol)
}
}
}
}
return "{undefined}"
}
Expand Down Expand Up @@ -387,6 +396,11 @@ class KotlinTypeSignatureBuilder(private val firSession: FirSession) : JavaTypeS
s.append("}")
} else if (type is ConeCapturedType && type.lowerType == null) {
s.append("*")
} else if (type is ConeStubTypeForChainInference) {
if (type.typeArguments.isNotEmpty()) {
throw UnsupportedOperationException("Unsupported ConeTypeProjection contains type arguments" + type.javaClass.getName())
}
s.append(signature(type.constructor.variable))
} else {
throw IllegalArgumentException("Unsupported ConeTypeProjection " + type.javaClass.getName())
}
Expand Down
27 changes: 19 additions & 8 deletions src/test/java/org/openrewrite/kotlin/KotlinTypeMappingTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@

import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import org.junitpioneer.jupiter.ExpectedToFail;
import org.openrewrite.InMemoryExecutionContext;
import org.openrewrite.Issue;
import org.openrewrite.internal.StringUtils;
import org.openrewrite.java.MethodMatcher;
import org.openrewrite.java.tree.Flag;
import org.openrewrite.java.tree.J;
import org.openrewrite.java.tree.JavaType;
Expand All @@ -29,6 +29,7 @@
import org.openrewrite.test.RewriteTest;

import java.util.List;
import java.util.concurrent.atomic.AtomicBoolean;

import static java.util.Objects.requireNonNull;
import static org.assertj.core.api.Assertions.assertThat;
Expand Down Expand Up @@ -306,18 +307,28 @@ void javaLangObject() {
class ParsingTest implements RewriteTest {
@Test
@Issue("https://github.com/openrewrite/rewrite-kotlin/issues/303")
@ExpectedToFail
void coneTypeProjection() {
rewriteRun(
kotlin(
"""
val labels: List<String> = listOf("")
val label: String = ""
val newLabels = buildList {
addAll(labels)
add(label)
val newList = buildList {
addAll(listOf(""))
}
"""
""", spec -> spec.afterRecipe(cu -> {
MethodMatcher methodMatcher = new MethodMatcher("kotlin.collections.MutableList addAll(..)");
AtomicBoolean found = new AtomicBoolean(false);
new KotlinIsoVisitor<AtomicBoolean>() {
@Override
public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, AtomicBoolean found) {
if (methodMatcher.matches(method)) {
assertThat(method.getMethodType().toString()).isEqualTo("kotlin.collections.MutableList<Generic{E}>{name=addAll,return=kotlin.Boolean,parameters=[kotlin.collections.Collection<Generic{E}>]}");
found.set(true);
}
return super.visitMethodInvocation(method, found);
}
}.visit(cu, found);
assertThat(found.get()).isTrue();
})
)
);
}
Expand Down
Loading