/* * Copyright (c) 2023-2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ class A {} class B extends A {} class C extends B {} class D extends C {} class F extends B {} class GenA {} class GenB extends GenA {} final class GenC extends GenB {} final class GenD extends GenB {} function foo(p: Object): int { return 0; } function foo(p: GenA): int { return 1; } function foo(p: GenA): int { return 2; } function foo(p: GenB): int { return 3; } function foo(p: GenB): int { return 4; } function foo(p: GenB): int { return 5; } function foo(p: GenB): int { return 6; } function foo(p: GenC): int { return 7; } function foo(p: GenC): int { return 8; } function foo(p: GenC): int { return 9; } function foo(p: GenC): int { return 10; } function main(): void { let a = true ? new GenB : new GenB; let test_a : GenB = a; assert (foo(a) == foo(new GenB)); let b = true ? new GenD : new GenC; let test_b : GenB = b; assert (foo(b) == 0); // foo(b) would call signature 'foo(p: GenB)', // but it's not declared (erased signature would // clash with other foo(p: GenB<*>) signatures), // so it's calling 'foo(p: Object)', which returns 0 let c = true ? new GenC : new GenC; let test_c : GenC = c; assert (foo(c) == foo(new GenC)); let d = true ? new GenA : new GenB; let test_d : GenA = d; assert (foo(d) == foo(new GenA)); let f = true ? new GenB : new GenB; let test_f : GenB = f; assert (foo(f) == foo(new GenB)); }