1/*
2 * Copyright (c) 2024 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16class A {
17  name = c'A'
18}
19class B extends A {
20  name = c'B'
21}
22class C extends B {
23  name = c'C';
24}
25
26function clear_accumlator_type(As: A[]): A[] {
27  return As;
28}
29
30function main() {
31  {
32    let As: A[] = new C[1];
33    As[0] = new C();
34
35    As = clear_accumlator_type(As); // workaround for:
36    // Verifier warning 22: Redundant check cast
37    // Accumulator type 'C[]' is always a subtype of 'B[]'. Checkcast is redundant here.
38    // It may be a sign of possible error here.
39    let Bs: B[] = As as B[];
40    assert Bs[0].name == c'B';
41  }
42
43  {
44    let caught = false;
45    try {
46      let As: A[] = new A[1];
47      let Bs = As as B[];
48    } catch (e: ClassCastError) {
49      caught = true;
50    } catch (e) {
51      assert false;
52    }
53    assert caught;
54  }
55}
56