1 /* 2 * Copyright 2021 The Android Open Source Project 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 @file:Suppress("unused", "ObjectLiteralToLambda", "UNUSED_VARIABLE") 17 18 package sample.optin 19 20 /** 21 * Regression test for b/192562926 where the lint check should not flag overrides where there is no 22 * dependency on the superclass, e.g. calls to super(). 23 */ 24 class RegressionTestKotlin192562926 { 25 internal fun interface StableInterface { 26 // This method will show up first in the list provided by PsiClass.allMethods, but it's 27 // not the method that we want to inspect since it has a concrete implementation. abstractMethodWithDefaultnull28 fun abstractMethodWithDefault() {} 29 experimentalMethodnull30 @ExperimentalKotlinAnnotation fun experimentalMethod() 31 } 32 33 /** Unsafe override since super is not called. */ 34 internal class ConcreteStableInterface : StableInterface { 35 override fun experimentalMethod() {} // unsafe override 36 } 37 38 /** Test different approaches to overriding interface methods. */ regressionTestOverridesnull39 fun regressionTestOverrides() { 40 val anonymous: StableInterface = 41 object : StableInterface { 42 override fun experimentalMethod() {} // unsafe override 43 } 44 val lambda = StableInterface {} // unsafe override, but Kotlin compiler does not detect 45 } 46 } 47