1 /* 2 * Copyright 2020 The JSpecify Authors. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 import org.jspecify.annotations.NullMarked; 17 import org.jspecify.annotations.Nullable; 18 import org.jspecify.annotations.NullnessUnspecified; 19 20 @NullMarked 21 class UseOfTypeVariableAsTypeArgument { 22 interface Lib<T extends @Nullable Object> {} 23 24 interface Super<T extends @Nullable Object> { get()25 Lib<T> get(); 26 } 27 28 interface SubObject extends Super<Object> {} 29 30 interface SubObjectUnspec extends Super<@NullnessUnspecified Object> {} 31 32 interface SubObjectUnionNull extends Super<@Nullable Object> {} 33 34 class Caller { x0(SubObject s)35 Lib<? extends Object> x0(SubObject s) { 36 return s.get(); 37 } 38 x1(SubObjectUnspec s)39 Lib<? extends Object> x1(SubObjectUnspec s) { 40 // jspecify_nullness_not_enough_information 41 return s.get(); 42 } 43 x2(SubObjectUnionNull s)44 Lib<? extends Object> x2(SubObjectUnionNull s) { 45 // jspecify_nullness_mismatch 46 return s.get(); 47 } 48 x3(Super<Object> s)49 Lib<? extends Object> x3(Super<Object> s) { 50 return s.get(); 51 } 52 x4(Super<@NullnessUnspecified Object> s)53 Lib<? extends Object> x4(Super<@NullnessUnspecified Object> s) { 54 // jspecify_nullness_not_enough_information 55 return s.get(); 56 } 57 x5(Super<@Nullable Object> s)58 Lib<? extends Object> x5(Super<@Nullable Object> s) { 59 // jspecify_nullness_mismatch 60 return s.get(); 61 } 62 x6(Super<? extends Object> s)63 Lib<? extends Object> x6(Super<? extends Object> s) { 64 return s.get(); 65 } 66 x7(Super<? extends @NullnessUnspecified Object> s)67 Lib<? extends Object> x7(Super<? extends @NullnessUnspecified Object> s) { 68 // jspecify_nullness_not_enough_information 69 return s.get(); 70 } 71 x8(Super<? extends @Nullable Object> s)72 Lib<? extends Object> x8(Super<? extends @Nullable Object> s) { 73 // jspecify_nullness_mismatch 74 return s.get(); 75 } 76 x9(Super<?> s)77 Lib<? extends Object> x9(Super<?> s) { 78 // jspecify_nullness_mismatch 79 return s.get(); 80 } 81 } 82 } 83