From 9d538dad8ae1dce4cc17ef5350d9f1ecb22de863 Mon Sep 17 00:00:00 2001 From: Andrey Breslav Date: Thu, 10 Jan 2013 15:30:03 +0400 Subject: [PATCH] EA-36903 - ISE: JavaTypeTransformer$.visitClassType Fixed --- .../resolve/java/JavaTypeTransformer.java | 13 +++++++--- .../tests/generics/PseudoRawTypes.kt | 24 +++++++++++++++++++ .../jet/CompileCompilerDependenciesTest.java | 15 ++++++++++-- .../checkers/AbstractJetDiagnosticsTest.java | 10 ++++---- .../checkers/JetDiagnosticsTestGenerated.java | 10 ++++---- 5 files changed, 58 insertions(+), 14 deletions(-) create mode 100644 compiler/testData/diagnostics/tests/generics/PseudoRawTypes.kt diff --git a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/JavaTypeTransformer.java b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/JavaTypeTransformer.java index 222c15b9f86..7e3a2b706e8 100644 --- a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/JavaTypeTransformer.java +++ b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/JavaTypeTransformer.java @@ -158,8 +158,8 @@ public class JavaTypeTransformer { } List arguments = Lists.newArrayList(); - if (classType.isRaw()) { - List parameters = classData.getTypeConstructor().getParameters(); + List parameters = classData.getTypeConstructor().getParameters(); + if (isRaw(classType, !parameters.isEmpty())) { for (TypeParameterDescriptor parameter : parameters) { TypeProjection starProjection = SubstitutionUtils.makeStarProjection(parameter); if (howThisTypeIsUsed == SUPERTYPE) { @@ -172,7 +172,6 @@ public class JavaTypeTransformer { } } else { - List parameters = classData.getTypeConstructor().getParameters(); PsiType[] psiArguments = classType.getParameters(); if (parameters.size() != psiArguments.length) { @@ -252,4 +251,12 @@ public class JavaTypeTransformer { }); return result; } + + private static boolean isRaw(@NotNull PsiClassType classType, boolean argumentsExpected) { + // The second option is needed because sometimes we get weird versions of JDK classes in teh class path, + // such as collections with no generics, so the Java types are not raw, formally, but they don't match with + // their Kotlin analogs, so we treat them as raw to avoid exceptions + return classType.isRaw() || argumentsExpected && classType.getParameterCount() == 0; + } + } diff --git a/compiler/testData/diagnostics/tests/generics/PseudoRawTypes.kt b/compiler/testData/diagnostics/tests/generics/PseudoRawTypes.kt new file mode 100644 index 00000000000..4716ee25328 --- /dev/null +++ b/compiler/testData/diagnostics/tests/generics/PseudoRawTypes.kt @@ -0,0 +1,24 @@ +// FILE: java/util/Collection.java +package java.util; + +public class Collection { + public void foo() {} +} + +// FILE: test/Usage.java +package test; + +import java.util.*; + +public class Usage { + void foo(Collection c) { + c.foo(); + } +} + +// FILE: Kotlin.kt +package test + +fun foo(u: Usage) { + u.foo(null) +} diff --git a/compiler/tests/org/jetbrains/jet/CompileCompilerDependenciesTest.java b/compiler/tests/org/jetbrains/jet/CompileCompilerDependenciesTest.java index cca7d69d737..8e4fedd3bb9 100644 --- a/compiler/tests/org/jetbrains/jet/CompileCompilerDependenciesTest.java +++ b/compiler/tests/org/jetbrains/jet/CompileCompilerDependenciesTest.java @@ -26,10 +26,13 @@ import org.junit.Test; import java.io.File; import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; import static org.jetbrains.jet.ConfigurationKind.ALL; import static org.jetbrains.jet.ConfigurationKind.JDK_AND_ANNOTATIONS; -import static org.jetbrains.jet.cli.jvm.JVMConfigurationKeys.*; +import static org.jetbrains.jet.cli.jvm.JVMConfigurationKeys.ANNOTATIONS_PATH_KEY; +import static org.jetbrains.jet.cli.jvm.JVMConfigurationKeys.CLASSPATH_KEY; public class CompileCompilerDependenciesTest { @@ -48,14 +51,22 @@ public class CompileCompilerDependenciesTest { ForTestCompileRuntime.runtimeJarForTests(); } + @NotNull public static CompilerConfiguration compilerConfigurationForTests(@NotNull ConfigurationKind configurationKind, @NotNull TestJdkKind jdkKind, File... extraClasspath) { + return compilerConfigurationForTests(configurationKind, jdkKind, Arrays.asList(extraClasspath), Collections.emptyList()); + } + + @NotNull + public static CompilerConfiguration compilerConfigurationForTests(@NotNull ConfigurationKind configurationKind, + @NotNull TestJdkKind jdkKind, @NotNull Collection extraClasspath, @NotNull Collection priorityClasspath) { CompilerConfiguration configuration = new CompilerConfiguration(); + configuration.addAll(CLASSPATH_KEY, priorityClasspath); configuration.add(CLASSPATH_KEY, jdkKind == TestJdkKind.MOCK_JDK ? JetTestUtils.findMockJdkRtJar() : PathUtil.findRtJar()); if (configurationKind == ALL) { configuration.add(CLASSPATH_KEY, ForTestCompileRuntime.runtimeJarForTests()); } - configuration.addAll(CLASSPATH_KEY, Arrays.asList(extraClasspath)); + configuration.addAll(CLASSPATH_KEY, extraClasspath); if (configurationKind == ALL || configurationKind == JDK_AND_ANNOTATIONS) { configuration.add(ANNOTATIONS_PATH_KEY, ForTestPackJdkAnnotations.jdkAnnotationsForTests()); diff --git a/compiler/tests/org/jetbrains/jet/checkers/AbstractJetDiagnosticsTest.java b/compiler/tests/org/jetbrains/jet/checkers/AbstractJetDiagnosticsTest.java index e7e15c44561..ad9e7e1b95a 100644 --- a/compiler/tests/org/jetbrains/jet/checkers/AbstractJetDiagnosticsTest.java +++ b/compiler/tests/org/jetbrains/jet/checkers/AbstractJetDiagnosticsTest.java @@ -30,13 +30,13 @@ import org.jetbrains.jet.cli.jvm.compiler.JetCoreEnvironment; import org.jetbrains.jet.lang.diagnostics.Diagnostic; import org.jetbrains.jet.lang.diagnostics.DiagnosticUtils; import org.jetbrains.jet.lang.psi.JetFile; -import org.jetbrains.jet.lang.resolve.AnalyzingUtils; import org.jetbrains.jet.lang.resolve.BindingContext; import org.jetbrains.jet.utils.ExceptionUtils; import java.io.File; import java.io.IOException; import java.nio.charset.Charset; +import java.util.Arrays; import java.util.List; public abstract class AbstractJetDiagnosticsTest extends JetLiteFixture { @@ -53,10 +53,10 @@ public abstract class AbstractJetDiagnosticsTest extends JetLiteFixture { return new JetCoreEnvironment( getTestRootDisposable(), CompileCompilerDependenciesTest.compilerConfigurationForTests( - ConfigurationKind.JDK_AND_ANNOTATIONS, - TestJdkKind.MOCK_JDK, - JetTestUtils.getAnnotationsJar(), - javaFilesDir + ConfigurationKind.JDK_AND_ANNOTATIONS, + TestJdkKind.MOCK_JDK, + Arrays.asList(JetTestUtils.getAnnotationsJar()), + Arrays.asList(javaFilesDir) ) ); } diff --git a/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java b/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java index 0316a6b98a3..66fe290258e 100644 --- a/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java @@ -15,16 +15,13 @@ */ package org.jetbrains.jet.checkers; -import junit.framework.Assert; import junit.framework.Test; import junit.framework.TestSuite; - -import java.io.File; import org.jetbrains.jet.JetTestUtils; import org.jetbrains.jet.test.InnerTestClasses; import org.jetbrains.jet.test.TestMetadata; -import org.jetbrains.jet.checkers.AbstractDiagnosticsTestWithEagerResolve; +import java.io.File; /** This class is generated by {@link org.jetbrains.jet.generators.tests.GenerateTests}. DO NOT MODIFY MANUALLY */ @InnerTestClasses({JetDiagnosticsTestGenerated.Tests.class, JetDiagnosticsTestGenerated.Script.class}) @@ -1839,6 +1836,11 @@ public class JetDiagnosticsTestGenerated extends AbstractDiagnosticsTestWithEage doTest("compiler/testData/diagnostics/tests/generics/Projections.kt"); } + @TestMetadata("PseudoRawTypes.kt") + public void testPseudoRawTypes() throws Exception { + doTest("compiler/testData/diagnostics/tests/generics/PseudoRawTypes.kt"); + } + @TestMetadata("RawTypeInIsExpression.kt") public void testRawTypeInIsExpression() throws Exception { doTest("compiler/testData/diagnostics/tests/generics/RawTypeInIsExpression.kt");