Return error class in case we are not able to find class for object property

This commit is contained in:
Pavel V. Talanov
2013-09-02 15:30:49 +04:00
parent 2e823d6b7b
commit e4b2e32827
4 changed files with 20 additions and 2 deletions
@@ -28,6 +28,7 @@ import org.jetbrains.jet.lang.resolve.DescriptorUtils;
import org.jetbrains.jet.lang.resolve.lazy.storage.StorageManager;
import org.jetbrains.jet.lang.resolve.name.FqNameUnsafe;
import org.jetbrains.jet.lang.resolve.name.Name;
import org.jetbrains.jet.lang.types.ErrorUtils;
import org.jetbrains.jet.lang.types.Variance;
import java.util.ArrayList;
@@ -201,8 +202,11 @@ public class DescriptorDeserializer {
FqNameUnsafe fqName = DescriptorUtils.getFQName(containingDeclaration).child(name);
ClassId objectId = ClassId.fromFqNameAndContainingDeclaration(fqName, (ClassOrNamespaceDescriptor) containingDeclaration);
ClassDescriptor objectClass = typeDeserializer.getDescriptorFinder().findClass(objectId);
assert objectClass != null : "Object for property not found: " + name;
if (objectClass == null) {
// if we are not able to find the class for object property
// then something bad has happened since they should be in the same jar
objectClass = ErrorUtils.createErrorClass(objectId.asSingleFqName().asString());
}
return new PropertyDescriptorForObjectImpl(containingDeclaration, annotations, visibility, name, objectClass);
}
@@ -43,4 +43,17 @@ public final class CompileKotlinAgainstBinariesCustomTest extends AbstractCompil
Assert.assertFalse("Object property should have valid class", ErrorUtils.isError(((VariableDescriptorForObject) descriptor).getObjectClass()));
}
}
public void testBrokenJarWithNoClassForObjectProperty() throws Exception {
BindingContext context = analyzeFile(new File(
"compiler/testData/compileKotlinAgainstBinariesCustom/brokenJarWithNoClassForObjectProperty/brokenJarWithNoClassForObjectProperty.kt"));
NamespaceDescriptor namespaceDescriptor = context.get(FQNAME_TO_NAMESPACE_DESCRIPTOR, TEST_PACKAGE_FQNAME);
assert namespaceDescriptor != null;
Collection<DeclarationDescriptor> allDescriptors = namespaceDescriptor.getMemberScope().getAllDescriptors();
Assert.assertEquals(allDescriptors.size(), 1);
DeclarationDescriptor descriptor = allDescriptors.iterator().next();
Assert.assertTrue(descriptor.getName().asString().equals("Lol"));
Assert.assertTrue(descriptor instanceof VariableDescriptorForObject);
Assert.assertTrue("Object property should have an error class", ErrorUtils.isError(((VariableDescriptorForObject) descriptor).getObjectClass()));
}
}