1*2167191dSAndroid Build Coastguard Worker /* 2*2167191dSAndroid Build Coastguard Worker * Copyright 2020 The JSpecify Authors. 3*2167191dSAndroid Build Coastguard Worker * 4*2167191dSAndroid Build Coastguard Worker * Licensed under the Apache License, Version 2.0 (the "License"); 5*2167191dSAndroid Build Coastguard Worker * you may not use this file except in compliance with the License. 6*2167191dSAndroid Build Coastguard Worker * You may obtain a copy of the License at 7*2167191dSAndroid Build Coastguard Worker * 8*2167191dSAndroid Build Coastguard Worker * http://www.apache.org/licenses/LICENSE-2.0 9*2167191dSAndroid Build Coastguard Worker * 10*2167191dSAndroid Build Coastguard Worker * Unless required by applicable law or agreed to in writing, software 11*2167191dSAndroid Build Coastguard Worker * distributed under the License is distributed on an "AS IS" BASIS, 12*2167191dSAndroid Build Coastguard Worker * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13*2167191dSAndroid Build Coastguard Worker * See the License for the specific language governing permissions and 14*2167191dSAndroid Build Coastguard Worker * limitations under the License. 15*2167191dSAndroid Build Coastguard Worker */ 16*2167191dSAndroid Build Coastguard Worker import org.jspecify.annotations.NullMarked; 17*2167191dSAndroid Build Coastguard Worker import org.jspecify.annotations.Nullable; 18*2167191dSAndroid Build Coastguard Worker 19*2167191dSAndroid Build Coastguard Worker @NullMarked 20*2167191dSAndroid Build Coastguard Worker abstract class AugmentedInferenceAgreesWithBaseInference { x(Foo<Object> a, Foo<@Nullable Object> b)21*2167191dSAndroid Build Coastguard Worker void x(Foo<Object> a, Foo<@Nullable Object> b) { 22*2167191dSAndroid Build Coastguard Worker // List of possibly heterogeneous Foo types. 23*2167191dSAndroid Build Coastguard Worker List<Foo<?>> l1 = makeList(a, b); 24*2167191dSAndroid Build Coastguard Worker 25*2167191dSAndroid Build Coastguard Worker /* 26*2167191dSAndroid Build Coastguard Worker * List of some unspecified homogeneous Foo type. There is such a type under plain Java (since 27*2167191dSAndroid Build Coastguard Worker * the base type for both is Foo<Object>) but not under JSpecify (since one is Foo<Object> and 28*2167191dSAndroid Build Coastguard Worker * the other is Foo<@Nullable Object>). 29*2167191dSAndroid Build Coastguard Worker * 30*2167191dSAndroid Build Coastguard Worker * Notice that `makeList(a, b)` is fine "in a vacuum" even under JSpecify (as shown above). Only 31*2167191dSAndroid Build Coastguard Worker * here, where the type of the expression is forced to conform to the target type, is there a 32*2167191dSAndroid Build Coastguard Worker * problem. 33*2167191dSAndroid Build Coastguard Worker */ 34*2167191dSAndroid Build Coastguard Worker // jspecify_nullness_mismatch 35*2167191dSAndroid Build Coastguard Worker List<? extends Foo<?>> l2 = makeList(a, b); 36*2167191dSAndroid Build Coastguard Worker } 37*2167191dSAndroid Build Coastguard Worker makeList(T a, T b)38*2167191dSAndroid Build Coastguard Worker abstract <T extends @Nullable Object> List<T> makeList(T a, T b); 39*2167191dSAndroid Build Coastguard Worker 40*2167191dSAndroid Build Coastguard Worker interface Foo<T extends @Nullable Object> {} 41*2167191dSAndroid Build Coastguard Worker 42*2167191dSAndroid Build Coastguard Worker interface List<T extends @Nullable Object> {} 43*2167191dSAndroid Build Coastguard Worker } 44