Home | History | Annotate | Download | only in src
      1 /*
      2  * Copyright (C) 2016 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 
     17 class SuperClass {
     18 }
     19 
     20 class ChildClass extends SuperClass {
     21 }
     22 
     23 public class Main {
     24 
     25   /// CHECK-START:    void Main.main(java.lang.String[]) builder (after)
     26   /// CHECK:          BoundType  klass:SuperClass can_be_null:false exact:false
     27 
     28   /// CHECK-START:    void Main.main(java.lang.String[]) builder (after)
     29   /// CHECK-NOT:      BoundType  klass:SuperClass can_be_null:false exact:true
     30   public static void main(String[] args) {
     31     Object obj = new ChildClass();
     32 
     33     // We need a fixed point iteration to hit the bogus type update
     34     // of 'obj' below, so create a loop that updates the type of 'obj'.
     35     for (int i = 1; i < 1; i++) {
     36       obj = new Object();
     37     }
     38 
     39     if (obj instanceof SuperClass) {
     40       // We used to wrongly type obj as an exact SuperClass from this point,
     41       // meaning we were statically determining that the following instanceof
     42       // would always fail.
     43       if (!(obj instanceof ChildClass)) {
     44         throw new Error("Expected a ChildClass, got " + obj.getClass());
     45       }
     46     }
     47   }
     48 }
     49