• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

rokucommunity / brighterscript / #13308

22 Nov 2024 02:25PM UTC coverage: 86.801%. Remained the same
#13308

push

web-flow
Merge 332332a1f into 2a6afd921

11833 of 14419 branches covered (82.07%)

Branch coverage included in aggregate %.

191 of 205 new or added lines in 26 files covered. (93.17%)

201 existing lines in 18 files now uncovered.

12868 of 14038 relevant lines covered (91.67%)

32022.22 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

86.75
/src/types/ArrayType.ts
1

2
import { SymbolTypeFlag } from '../SymbolTypeFlag';
1✔
3
import { isArrayType, isDynamicType, isObjectType } from '../astUtils/reflection';
1✔
4
import type { TypeCompatibilityData } from '../interfaces';
5
import { BscType } from './BscType';
1✔
6
import { BscTypeKind } from './BscTypeKind';
1✔
7
import type { BuiltInInterfaceOverride } from './BuiltInInterfaceAdder';
8
import { BuiltInInterfaceAdder } from './BuiltInInterfaceAdder';
1✔
9
import { DynamicType } from './DynamicType';
1✔
10
import { IntegerType } from './IntegerType';
1✔
11
import { unionTypeFactory } from './UnionType';
1✔
12
import { getUniqueType, isUnionTypeCompatible } from './helpers';
1✔
13

14
export class ArrayType extends BscType {
1✔
15
    constructor(...innerTypes: BscType[]) {
16
        super();
161,420✔
17
        this.innerTypes = innerTypes;
161,420✔
18
    }
19

20
    public readonly kind = BscTypeKind.ArrayType;
161,420✔
21
    public isBuiltIn = true;
161,420✔
22

23
    public innerTypes: BscType[] = [];
161,420✔
24

25
    public get defaultType(): BscType {
26
        if (this.innerTypes?.length === 0) {
3,919!
27
            return DynamicType.instance;
3,600✔
28
        } else if (this.innerTypes?.length === 1) {
319!
29
            return this.innerTypes[0];
288✔
30
        }
31
        return getUniqueType(this.innerTypes, unionTypeFactory);
31✔
32
    }
33

34
    public isTypeCompatible(targetType: BscType, data?: TypeCompatibilityData) {
35

36
        if (isDynamicType(targetType)) {
17✔
37
            return true;
1✔
38
        } else if (isObjectType(targetType)) {
16✔
39
            return true;
2✔
40
        } else if (isUnionTypeCompatible(this, targetType)) {
14!
UNCOV
41
            return true;
×
42
        } else if (isArrayType(targetType)) {
14✔
43
            const compatible = this.defaultType.isTypeCompatible(targetType.defaultType, data);
10✔
44
            if (data) {
10✔
45
                data.actualType = targetType.defaultType;
6✔
46
                data.expectedType = this.defaultType;
6✔
47
            }
48
            return compatible;
10✔
49
        } else if (this.checkCompatibilityBasedOnMembers(targetType, SymbolTypeFlag.runtime, data)) {
4✔
50
            return true;
3✔
51
        }
52
        return false;
1✔
53
    }
54

55
    public toString() {
56
        return `Array<${this.defaultType.toString()}>`;
3,811✔
57
    }
58

59
    public toTypeString(): string {
UNCOV
60
        return 'object';
×
61
    }
62

63
    public isEqual(targetType: BscType): boolean {
64
        if (isArrayType(targetType)) {
3✔
65
            if (targetType.innerTypes.length !== this.innerTypes.length) {
1!
UNCOV
66
                return false;
×
67
            }
68
            for (let i = 0; i < this.innerTypes.length; i++) {
1✔
UNCOV
69
                if (!this.innerTypes[i].isEqual(targetType.innerTypes[i])) {
×
70
                    return false;
×
71
                }
72
            }
73
            return true;
1✔
74
        }
75
        return false;
2✔
76
    }
77

78
    addBuiltInInterfaces() {
79
        if (!this.hasAddedBuiltInInterfaces) {
96✔
80
            const overrideMap = new Map<string, BuiltInInterfaceOverride>();
17✔
81
            const defaultType = this.defaultType;
17✔
82
            overrideMap
17✔
83
                // ifArray
84
                .set('peek', { returnType: defaultType })
85
                .set('pop', { returnType: defaultType })
86
                .set('push', { parameterTypes: [defaultType] })
87
                .set('shift', { returnType: defaultType })
88
                .set('unshift', { parameterTypes: [defaultType] })
89
                .set('append', { parameterTypes: [this] })
90
                // ifArrayGet
91
                .set('get', { returnType: defaultType })
92
                // ifArraySet
93
                .set('get', { parameterTypes: [IntegerType.instance, defaultType] })
94
                //ifEnum
95
                .set('next', { returnType: defaultType });
96
            BuiltInInterfaceAdder.addBuiltInInterfacesToType(this, overrideMap);
17✔
97
        }
98
        this.hasAddedBuiltInInterfaces = true;
96✔
99
    }
100
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc