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 C<T> {
17    constructor (p: T) { this.v = p; }
18    v: T;
19}
20
21type Alias1Union<T1, T2> = T1 | T2;
22type Alias2Union<T1, T2> = C<T1> | T2;
23type Alias3Union<T1, T2> = C<T1>[] | T2;
24type Alias4Union<T1, T2> = (p: T1) => double | T2;
25
26function main() {
27    let v1 : double | double = new Int(1);    // primitive double
28    let v2 : double | string = 2;             // boxed Double|String
29
30    let v3 : Alias1Union<double, double> = new Int(3);  // primitive double
31    assert(v3 == 3);                           
32    let v4 : Alias1Union<double, string> = 4;          // boxed Double|String
33    assert(v4 == 4);
34
35    let v5 : Alias2Union<double, string> = new C<double>(5);  // C<Double>|String
36    let v6 : C<double> = v5 as C<double>;
37    assert(v6.v == 5);
38
39    let v7 : Alias3Union<double, string> = [new C<double>(6)];   // C<Double>[]|String
40    let v9 : C<double>[] = v7 as C<double>[];
41    assert (v9[0].v == 6);
42
43    let v10 : Alias4Union<double, string> = (p : double) : double => { return p; };  // (p: Double)=>Double |String
44    let v11 : (p : double) => double = v10 as (p : double) => double;
45    assert (v11(7) == 7);
46}
47