KT-1961 Incorrect override error in functions with type parameter with two upper bounds

#KT-1961 Fixed
This commit is contained in:
Andrey Breslav
2012-05-11 18:00:09 +04:00
parent c63af879fa
commit 420a7c9ad4
3 changed files with 116 additions and 19 deletions
@@ -0,0 +1,100 @@
/*
* Copyright 2010-2012 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.jet.lang.types;
import com.google.common.collect.Sets;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.descriptors.ClassifierDescriptor;
import org.jetbrains.jet.lang.descriptors.TypeParameterDescriptor;
import org.jetbrains.jet.lang.descriptors.annotations.AnnotatedImpl;
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
import java.util.*;
/**
* @author abreslav
*/
public class IntersectionTypeConstructor extends AnnotatedImpl implements TypeConstructor {
private final Set<JetType> intersectedTypes;
private final int hashCode;
public IntersectionTypeConstructor(List<AnnotationDescriptor> annotations, Collection<JetType> typesToIntersect) {
super(annotations);
this.intersectedTypes = Sets.newLinkedHashSet(typesToIntersect);
this.hashCode = intersectedTypes.hashCode();
}
@NotNull
@Override
public List<TypeParameterDescriptor> getParameters() {
return Collections.emptyList();
}
@NotNull
@Override
public Collection<? extends JetType> getSupertypes() {
return intersectedTypes;
}
@Override
public boolean isSealed() {
return false;
}
@Override
public ClassifierDescriptor getDeclarationDescriptor() {
return null;
}
@Override
public String toString() {
return makeDebugNameForIntersectionType(intersectedTypes);
}
private static String makeDebugNameForIntersectionType(Iterable<JetType> resultingTypes) {
StringBuilder debugName = new StringBuilder("{");
for (Iterator<JetType> iterator = resultingTypes.iterator(); iterator.hasNext(); ) {
JetType type = iterator.next();
debugName.append(type.toString());
if (iterator.hasNext()) {
debugName.append(" & ");
}
}
debugName.append("}");
return debugName.toString();
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
IntersectionTypeConstructor that = (IntersectionTypeConstructor) o;
if (intersectedTypes != null ? !intersectedTypes.equals(that.intersectedTypes) : that.intersectedTypes != null) return false;
return true;
}
@Override
public int hashCode() {
return hashCode;
}
}
@@ -193,12 +193,8 @@ public class TypeUtils {
List<AnnotationDescriptor> noAnnotations = Collections.<AnnotationDescriptor>emptyList();
TypeConstructor constructor = new TypeConstructorImpl(
null,
TypeConstructor constructor = new IntersectionTypeConstructor(
noAnnotations,
false,
makeDebugNameForIntersectionType(resultingTypes).toString(),
Collections.<TypeParameterDescriptor>emptyList(),
resultingTypes);
JetScope[] scopes = new JetScope[resultingTypes.size()];
@@ -269,20 +265,6 @@ public class TypeUtils {
}
}
private static StringBuilder makeDebugNameForIntersectionType(Iterable<JetType> resultingTypes) {
StringBuilder debugName = new StringBuilder("{");
for (Iterator<JetType> iterator = resultingTypes.iterator(); iterator.hasNext(); ) {
JetType type = iterator.next();
debugName.append(type.toString());
if (iterator.hasNext()) {
debugName.append(" & ");
}
}
debugName.append("}");
return debugName;
}
public static boolean canHaveSubtypes(JetTypeChecker typeChecker, JetType type) {
if (type.isNullable()) {
return true;
@@ -0,0 +1,15 @@
trait Foo
trait Bar
trait A {
fun <T> foo()
where T : Foo, T : Bar
= #()
}
class B : A {
override fun <T> foo()
where T : Foo, T : Bar
= #()
}