don't use PSI for calculating the type of first argument of trait function implementation
This commit is contained in:
@@ -832,7 +832,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
||||
reg += argType.getSize();
|
||||
}
|
||||
|
||||
JetType jetType = TraitImplBodyCodegen.getSuperClass(declaration, bindingContext);
|
||||
JetType jetType = TraitImplBodyCodegen.getSuperClass(declaration);
|
||||
Type type = typeMapper.mapType(jetType, MapTypeMode.IMPL);
|
||||
if (type.getInternalName().equals("java/lang/Object")) {
|
||||
jetType = declaration.getDefaultType();
|
||||
|
||||
@@ -710,7 +710,7 @@ public class JetTypeMapper {
|
||||
|
||||
if (kind == OwnerKind.TRAIT_IMPL) {
|
||||
ClassDescriptor containingDeclaration = (ClassDescriptor) f.getContainingDeclaration();
|
||||
JetType jetType = TraitImplBodyCodegen.getSuperClass(containingDeclaration, bindingContext);
|
||||
JetType jetType = TraitImplBodyCodegen.getSuperClass(containingDeclaration);
|
||||
Type type = mapType(jetType, MapTypeMode.VALUE);
|
||||
if(type.getInternalName().equals("java/lang/Object")) {
|
||||
jetType = containingDeclaration.getDefaultType();
|
||||
|
||||
@@ -16,12 +16,10 @@
|
||||
|
||||
package org.jetbrains.jet.codegen;
|
||||
|
||||
import com.intellij.psi.PsiClass;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContextUtils;
|
||||
import org.jetbrains.jet.lang.descriptors.ClassKind;
|
||||
import org.jetbrains.jet.lang.psi.JetClassOrObject;
|
||||
import org.jetbrains.jet.lang.resolve.DescriptorUtils;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
import org.jetbrains.jet.lang.types.lang.JetStandardClasses;
|
||||
import org.objectweb.asm.Opcodes;
|
||||
@@ -33,30 +31,11 @@ public class TraitImplBodyCodegen extends ClassBodyCodegen {
|
||||
super(aClass, context, v, state);
|
||||
}
|
||||
|
||||
//todo not needed when frontend will be able to calculate properly
|
||||
static JetType getSuperClass(ClassDescriptor myClassDescr, BindingContext bindingContext) {
|
||||
JetClassOrObject myClass = (JetClassOrObject) BindingContextUtils.classDescriptorToDeclaration(bindingContext, myClassDescr);
|
||||
if (myClass == null)
|
||||
return JetStandardClasses.getAnyType();
|
||||
List<JetDelegationSpecifier> delegationSpecifiers = myClass.getDelegationSpecifiers();
|
||||
|
||||
for (JetDelegationSpecifier specifier : delegationSpecifiers) {
|
||||
if (specifier instanceof JetDelegatorToSuperClass || specifier instanceof JetDelegatorToSuperCall) {
|
||||
JetType superType = bindingContext.get(BindingContext.TYPE, specifier.getTypeReference());
|
||||
ClassDescriptor superClassDescriptor = (ClassDescriptor) superType.getConstructor().getDeclarationDescriptor();
|
||||
final PsiElement declaration = BindingContextUtils.classDescriptorToDeclaration(bindingContext, superClassDescriptor);
|
||||
if (declaration != null) {
|
||||
if (declaration instanceof PsiClass) {
|
||||
if (!((PsiClass) declaration).isInterface()) {
|
||||
return superClassDescriptor.getDefaultType();
|
||||
}
|
||||
}
|
||||
else if (declaration instanceof JetClass) {
|
||||
if (!((JetClass) declaration).isTrait()) {
|
||||
return superClassDescriptor.getDefaultType();
|
||||
}
|
||||
}
|
||||
}
|
||||
static JetType getSuperClass(ClassDescriptor classDescriptor) {
|
||||
final List<ClassDescriptor> superclassDescriptors = DescriptorUtils.getSuperclassDescriptors(classDescriptor);
|
||||
for (ClassDescriptor descriptor : superclassDescriptors) {
|
||||
if (descriptor.getKind() != ClassKind.TRAIT) {
|
||||
return descriptor.getDefaultType();
|
||||
}
|
||||
}
|
||||
return JetStandardClasses.getAnyType();
|
||||
|
||||
Reference in New Issue
Block a user