[java] [inference] limit bound promotion per one parameter (IDEA-277612)

GitOrigin-RevId: 0ed133250f1c68c5c14b5e6c5683b03084592e1d
This commit is contained in:
Anna Kozlova
2021-09-14 06:40:42 +00:00
committed by intellij-monorepo-bot
parent bd40d80a9a
commit dea5a38f11
3 changed files with 32 additions and 34 deletions
@@ -1,18 +1,4 @@
/*
* Copyright 2000-2016 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.
*/
// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.psi.impl.source.resolve.graphInference.constraints;
import com.intellij.core.JavaPsiBundle;
@@ -24,9 +10,7 @@ import com.intellij.psi.util.InheritanceUtil;
import com.intellij.psi.util.PsiUtil;
import com.intellij.psi.util.TypeConversionUtil;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.*;
public class StrictSubtypingConstraint implements ConstraintFormula {
private PsiType myS;
@@ -138,9 +122,11 @@ public class StrictSubtypingConstraint implements ConstraintFormula {
}
PsiSubstitutor substitutor = SResult.getSubstitutor();
Map<PsiTypeParameter, PsiType> map = new HashMap<>();
for (PsiTypeParameter typeParameter : SClass.getTypeParameters()) {
substitutor = substitutor.put(typeParameter, substitutor.substituteWithBoundsPromotion(typeParameter));
map.put(typeParameter, substitutor.substituteWithBoundsPromotion(typeParameter));
}
substitutor = substitutor.putAll(map);
final PsiSubstitutor tSubstitutor = TResult.getSubstitutor();
final PsiSubstitutor sSubstitutor = TypeConversionUtil.getClassSubstitutor(CClass, SClass, substitutor);
@@ -0,0 +1,25 @@
import java.util.Collection;
import java.util.List;
interface Mappable<T> {
T map(Mapper mapper);
class Foo<B extends Foo.FooBuilder<B, U>, U extends Foo<B, U>> implements Mappable<Foo<B, U>> {
static class FooBuilder<B extends FooBuilder<B, U>, U extends Foo<B, U>> {}
@Override
public Foo<B, U> map(Mapper mapper) { return this; }
}
class Mapper {
<E extends Mappable<? extends E>> List<E> map(List<E> in) { return in; }
<E extends Mappable<? extends E>> Collection<E> map(Collection<E> in) { return in; }
}
class Counter implements Mappable<Counter> {
private final List<Foo<?, ?>> in;
Counter(List<Foo<?, ?>> in) { this.in = in; }
@Override
public Counter map(Mapper mapper) {
return new Counter(mapper.map(in));
}
}
}
@@ -1,18 +1,4 @@
/*
* Copyright 2000-2017 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.
*/
// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.java.codeInsight.daemon.lambda;
import com.intellij.codeInsight.daemon.LightDaemonAnalyzerTestCase;
@@ -207,6 +193,7 @@ public class GraphInferenceHighlightingTest extends LightDaemonAnalyzerTestCase
public void testLambdaInConditional() { doTest(); }
public void testTopLevelParentNoParameters() { doTest(); }
public void testRawTypeOnTheRight() { doTest(); }
public void testMutualBoundPromotion() { doTest(); }
private void doTest() {
doTest(false);