kill redeclaration handler in ClassDescriptor

This commit is contained in:
Stepan Koltsov
2012-02-19 22:02:37 +04:00
parent ca8cf6cb49
commit ea8eb7412a
9 changed files with 68 additions and 25 deletions
@@ -24,6 +24,7 @@ import org.jetbrains.jet.lang.resolve.BindingContext;
import org.jetbrains.jet.lang.resolve.BindingTrace;
import org.jetbrains.jet.lang.resolve.TraceBasedRedeclarationHandler;
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
import org.jetbrains.jet.lang.resolve.scopes.RedeclarationHandler;
import org.jetbrains.jet.lang.resolve.scopes.WritableScope;
import org.jetbrains.jet.lang.resolve.scopes.WritableScopeImpl;
import org.jetbrains.jet.lang.resolve.scopes.receivers.ClassReceiver;
@@ -57,7 +58,7 @@ public class MutableClassDescriptor extends MutableClassDescriptorLite {
throw new IllegalStateException();
}
TraceBasedRedeclarationHandler redeclarationHandler = new TraceBasedRedeclarationHandler(trace);
RedeclarationHandler redeclarationHandler = RedeclarationHandler.DO_NOTHING;
setScopeForMemberLookup(new WritableScopeImpl(JetScope.EMPTY, this, redeclarationHandler).setDebugName("MemberLookup").changeLockLevel(WritableScope.LockLevel.BOTH));
this.scopeForSupertypeResolution = new WritableScopeImpl(outerScope, this, redeclarationHandler).setDebugName("SupertypeResolution").changeLockLevel(WritableScope.LockLevel.BOTH);
@@ -103,7 +103,7 @@ public class OverloadResolver {
private void checkOverloadsInANamespace(MultiMap<Key, ConstructorDescriptor> inNamespaces) {
MultiMap<Key, FunctionDescriptor> functionsByName = MultiMap.create();
MultiMap<Key, CallableMemberDescriptor> functionsByName = MultiMap.create();
for (NamedFunctionDescriptor function : context.getFunctions().values()) {
DeclarationDescriptor containingDeclaration = function.getContainingDeclaration();
@@ -113,11 +113,19 @@ public class OverloadResolver {
}
}
for (PropertyDescriptor property : context.getProperties().values()) {
DeclarationDescriptor containingDeclaration = property.getContainingDeclaration();
if (containingDeclaration instanceof NamespaceDescriptor) {
NamespaceDescriptor namespaceDescriptor = (NamespaceDescriptor) containingDeclaration;
functionsByName.putValue(new Key(namespaceDescriptor, property.getName()), property);
}
}
for (Map.Entry<Key, Collection<ConstructorDescriptor>> entry : inNamespaces.entrySet()) {
functionsByName.putValues(entry.getKey(), entry.getValue());
}
for (Map.Entry<Key, Collection<FunctionDescriptor>> e : functionsByName.entrySet()) {
for (Map.Entry<Key, Collection<CallableMemberDescriptor>> e : functionsByName.entrySet()) {
checkOverloadsWithSameName(e.getKey().getFunctionName(), e.getValue(), e.getKey().getNamespace());
}
}
@@ -140,17 +148,21 @@ public class OverloadResolver {
MutableClassDescriptor classDescriptor, JetClassOrObject klass,
Collection<ConstructorDescriptor> nestedClassConstructors)
{
MultiMap<String, FunctionDescriptor> functionsByName = MultiMap.create();
MultiMap<String, CallableMemberDescriptor> functionsByName = MultiMap.create();
for (FunctionDescriptor function : classDescriptor.getFunctions()) {
functionsByName.putValue(function.getName(), function);
}
for (PropertyDescriptor property : classDescriptor.getProperties()) {
functionsByName.putValue(property.getName(), property);
}
for (ConstructorDescriptor nestedClassConstructor : nestedClassConstructors) {
functionsByName.putValue(nestedClassConstructor.getContainingDeclaration().getName(), nestedClassConstructor);
}
for (Map.Entry<String, Collection<FunctionDescriptor>> e : functionsByName.entrySet()) {
for (Map.Entry<String, Collection<CallableMemberDescriptor>> e : functionsByName.entrySet()) {
checkOverloadsWithSameName(e.getKey(), e.getValue(), nameForErrorMessage(classDescriptor, klass));
}
@@ -160,14 +172,14 @@ public class OverloadResolver {
}
private void checkOverloadsWithSameName(String name, Collection<FunctionDescriptor> functions, @NotNull String functionContainer) {
private void checkOverloadsWithSameName(String name, Collection<CallableMemberDescriptor> functions, @NotNull String functionContainer) {
if (functions.size() == 1) {
// microoptimization
return;
}
for (FunctionDescriptor function : functions) {
for (FunctionDescriptor function2 : functions) {
for (CallableMemberDescriptor function : functions) {
for (CallableMemberDescriptor function2 : functions) {
if (function == function2) {
continue;
}
@@ -180,7 +192,11 @@ public class OverloadResolver {
return;
}
context.getTrace().report(Errors.CONFLICTING_OVERLOADS.on(member, function, functionContainer));
if (function instanceof PropertyDescriptor) {
context.getTrace().report(Errors.REDECLARATION.on(function, context.getTrace().getBindingContext()));
} else {
context.getTrace().report(Errors.CONFLICTING_OVERLOADS.on(member, function, functionContainer));
}
}
}
}
@@ -16,7 +16,10 @@
package org.jetbrains.jet.lang.resolve;
import org.jetbrains.jet.lang.descriptors.FunctionDescriptor;
import org.jetbrains.jet.lang.descriptors.CallableDescriptor;
import org.jetbrains.jet.lang.descriptors.ConstructorDescriptor;
import org.jetbrains.jet.lang.descriptors.NamedFunctionDescriptor;
import org.jetbrains.jet.lang.descriptors.PropertyDescriptor;
/**
* @author Stepan Koltsov
@@ -26,18 +29,37 @@ public class OverloadUtil {
/**
* Does not check names.
*/
public static OverloadCompatibilityInfo isOverloadble(FunctionDescriptor a, FunctionDescriptor b) {
public static OverloadCompatibilityInfo isOverloadble(CallableDescriptor a, CallableDescriptor b) {
int abc = braceCount(a);
int bbc = braceCount(b);
if (abc != bbc) {
return OverloadCompatibilityInfo.success();
}
OverridingUtil.OverrideCompatibilityInfo overrideCompatibilityInfo = OverridingUtil.isOverridableByImpl(a, b, false);
switch (overrideCompatibilityInfo.isOverridable()) {
case OVERRIDABLE:
return OverloadCompatibilityInfo.someError();
case CONFLICT:
return OverloadCompatibilityInfo.someError();
case INCOMPATIBLE:
return OverloadCompatibilityInfo.success();
default:
throw new IllegalStateException();
}
}
private static int braceCount(CallableDescriptor a) {
if (a instanceof PropertyDescriptor) {
return 0;
} else if (a instanceof NamedFunctionDescriptor) {
return 1;
} else if (a instanceof ConstructorDescriptor) {
return 1;
} else {
throw new IllegalStateException();
}
}
public static class OverloadCompatibilityInfo {
@@ -99,6 +99,8 @@ public class OverridingUtil {
if (superDescriptor instanceof PropertyDescriptor) {
if (subDescriptor instanceof FunctionDescriptor) return OverrideCompatibilityInfo.memberKindMismatch();
}
// TODO: check outside of this method
if (!superDescriptor.getName().equals(subDescriptor.getName())) {
return OverrideCompatibilityInfo.nameMismatch();
}
@@ -191,9 +193,11 @@ public class OverridingUtil {
JetType subValueParameterType = getUpperBound(subValueParameters.get(i));
// TODO: compare erasure
if (!JetTypeChecker.INSTANCE.equalTypes(superValueParameterType, subValueParameterType)) {
return OverrideCompatibilityInfo.valueParameterTypeMismatch(superValueParameterType, subValueParameterType, OverrideCompatibilityInfo.ErrorKind.CONFLICT);
return OverrideCompatibilityInfo.valueParameterTypeMismatch(superValueParameterType, subValueParameterType, OverrideCompatibilityInfo.ErrorKind.INCOMPATIBLE);
}
}
return OverrideCompatibilityInfo.success();
}
@@ -1,4 +1,4 @@
class Aaa() {
val <!REDECLARATION, REDECLARATION!>a<!> = 1
val <!REDECLARATION, REDECLARATION!>a<!> = 1
val <!REDECLARATION!>a<!> = 1
val <!REDECLARATION!>a<!> = 1
}
@@ -1,4 +1,4 @@
class Aaa() {
val <!REDECLARATION, REDECLARATION!>a<!> = 1
val <!REDECLARATION, REDECLARATION!>a<!> = ""
val <!REDECLARATION!>a<!> = 1
val <!REDECLARATION!>a<!> = ""
}
@@ -1,9 +1,9 @@
package override.generics
abstract class MyAbstractClass<T> {
abstract val <!REDECLARATION!>pr<!> : T
abstract val pr : T
}
abstract class MyLegalAbstractClass2<T>(t : T) : MyAbstractClass<Int>() {
<!CONFLICTING_OVERLOADS!>val <R> <!REDECLARATION!>pr<!> : T = t<!>
<!CONFLICTING_OVERLOADS!>val <R> pr : T = t<!>
}
@@ -1,7 +1,7 @@
open class Aaa() {
val <!REDECLARATION!>bar<!> = 1
val bar = 1
}
open class Bbb() : Aaa() {
<!CONFLICTING_OVERLOADS!>val <T> <!REDECLARATION!>bar<!> = "aa"<!>
<!CONFLICTING_OVERLOADS!>val <T> bar = "aa"<!>
}
@@ -6,7 +6,7 @@ trait MyTrait<T> {
abstract class MyAbstractClass<T> {
abstract fun bar(t: T) : T
abstract val <!REDECLARATION, REDECLARATION, REDECLARATION!>pr<!> : T
abstract val pr : T
}
trait MyProps<T> {
@@ -43,7 +43,7 @@ abstract class MyAbstractClass1 : MyTrait<Int>, MyAbstractClass<String>() {
class <!ABSTRACT_MEMBER_NOT_IMPLEMENTED!>MyIllegalGenericClass1<!><T> : MyTrait<T>, MyAbstractClass<T>() {}
class <!ABSTRACT_MEMBER_NOT_IMPLEMENTED!>MyIllegalGenericClass2<!><T, R>(r : R) : MyTrait<T>, MyAbstractClass<R>() {
<!NOTHING_TO_OVERRIDE!>override<!> fun foo(r: R) = r
<!CONFLICTING_OVERLOADS!><!NOTHING_TO_OVERRIDE!>override<!> val <T> <!REDECLARATION!>pr<!> : R = r<!>
<!CONFLICTING_OVERLOADS!><!NOTHING_TO_OVERRIDE!>override<!> val <T> pr : R = r<!>
}
class <!ABSTRACT_MEMBER_NOT_IMPLEMENTED!>MyIllegalClass1<!> : MyTrait<Int>, MyAbstractClass<String>() {}
abstract class MyLegalAbstractClass1 : MyTrait<Int>, MyAbstractClass<String>() {}
@@ -51,10 +51,10 @@ abstract class MyLegalAbstractClass1 : MyTrait<Int>, MyAbstractClass<String>() {
class <!ABSTRACT_MEMBER_NOT_IMPLEMENTED!>MyIllegalClass2<!><T>(t : T) : MyTrait<Int>, MyAbstractClass<Int>() {
fun foo(t: T) = t
fun bar(t: T) = t
<!CONFLICTING_OVERLOADS!>val <R> <!REDECLARATION!>pr<!> : T = t<!>
<!CONFLICTING_OVERLOADS!>val <R> pr : T = t<!>
}
abstract class MyLegalAbstractClass2<T>(t : T) : MyTrait<Int>, MyAbstractClass<Int>() {
fun foo(t: T) = t
fun bar(t: T) = t
<!CONFLICTING_OVERLOADS!>val <R> <!REDECLARATION!>pr<!> : T = t<!>
<!CONFLICTING_OVERLOADS!>val <R> pr : T = t<!>
}