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

rokucommunity / brighterscript / #15024

13 Dec 2025 02:11AM UTC coverage: 87.29% (-0.5%) from 87.825%
#15024

push

web-flow
Merge d8dcd8d52 into a65ebfcad

14406 of 17439 branches covered (82.61%)

Branch coverage included in aggregate %.

36 of 36 new or added lines in 4 files covered. (100.0%)

909 existing lines in 49 files now uncovered.

15091 of 16353 relevant lines covered (92.28%)

24217.12 hits per line

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

88.29
/src/types/ArrayType.ts
1

2
import { SymbolTypeFlag } from '../SymbolTypeFlag';
1✔
3
import { isArrayType, isDynamicType, isEnumMemberType, isInvalidType, 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
import { util } from '../util';
1✔
14

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

21
    public readonly kind = BscTypeKind.ArrayType;
190,885✔
22
    public isBuiltIn = true;
190,885✔
23

24
    public innerTypes: BscType[] = [];
190,885✔
25

26
    public _defaultType: BscType;
27
    private isCheckingInnerTypesForDefaultType = false;
190,885✔
28

29
    public get defaultType(): BscType {
30
        if (this._defaultType) {
5,538✔
31
            return this._defaultType;
1,102✔
32
        }
33
        if (this.innerTypes?.length === 0 || this.isCheckingInnerTypesForDefaultType) {
4,436!
34
            return DynamicType.instance;
4,255✔
35
        }
36
        this.isCheckingInnerTypesForDefaultType = true;
181✔
37

38
        let resultType = this.innerTypes[0];
181✔
39
        if (this.innerTypes?.length > 1) {
181!
40
            resultType = getUniqueType(this.innerTypes, unionTypeFactory) ?? DynamicType.instance;
31!
41
        }
42
        if (isEnumMemberType(resultType)) {
181✔
43
            resultType = resultType.parentEnumType ?? resultType;
2!
44
        }
45
        this._defaultType = util.getDefaultTypeFromValueType(resultType);
181✔
46
        this.isCheckingInnerTypesForDefaultType = false;
181✔
47
        return this._defaultType;
181✔
48
    }
49

50
    public isTypeCompatible(targetType: BscType, data?: TypeCompatibilityData) {
51

52
        if (isDynamicType(targetType)) {
25✔
53
            return true;
1✔
54
        } else if (isObjectType(targetType)) {
24✔
55
            return true;
3✔
56
        } else if (isInvalidType(targetType)) {
21✔
57
            return true;
5✔
58
        } else if (isUnionTypeCompatible(this, targetType)) {
16!
UNCOV
59
            return true;
×
60
        } else if (isArrayType(targetType)) {
16✔
61
            const compatible = this.defaultType.isTypeCompatible(targetType.defaultType, data);
10✔
62
            if (data) {
10✔
63
                data.actualType = targetType.defaultType;
6✔
64
                data.expectedType = this.defaultType;
6✔
65
            }
66
            return compatible;
10✔
67
        } else if (this.checkCompatibilityBasedOnMembers(targetType, SymbolTypeFlag.runtime, data)) {
6✔
68
            return true;
3✔
69
        }
70
        return false;
3✔
71
    }
72

73
    public toString() {
74
        return `Array<${this.defaultType.toString()}>`;
4,460✔
75
    }
76

77
    public toTypeString(): string {
UNCOV
78
        return 'object';
×
79
    }
80

81
    public isEqual(targetType: BscType): boolean {
82
        if (isArrayType(targetType)) {
3✔
83
            if (targetType.innerTypes.length !== this.innerTypes.length) {
1!
UNCOV
84
                return false;
×
85
            }
86
            for (let i = 0; i < this.innerTypes.length; i++) {
1✔
UNCOV
87
                if (!this.innerTypes[i].isEqual(targetType.innerTypes[i])) {
×
UNCOV
88
                    return false;
×
89
                }
90
            }
91
            return true;
1✔
92
        }
93
        return false;
2✔
94
    }
95

96
    addBuiltInInterfaces() {
97
        if (!this.hasAddedBuiltInInterfaces) {
127✔
98
            const overrideMap = new Map<string, BuiltInInterfaceOverride>();
56✔
99
            const defaultType = this.defaultType;
56✔
100
            overrideMap
56✔
101
                // ifArray
102
                .set('peek', { returnType: defaultType })
103
                .set('pop', { returnType: defaultType })
104
                .set('push', { parameterTypes: [defaultType] })
105
                .set('shift', { returnType: defaultType })
106
                .set('unshift', { parameterTypes: [defaultType] })
107
                .set('append', { parameterTypes: [this] })
108
                // ifArrayGet
109
                .set('get', { returnType: defaultType })
110
                // ifArraySet
111
                .set('get', { parameterTypes: [IntegerType.instance, defaultType] })
112
                //ifEnum
113
                .set('next', { returnType: defaultType });
114
            BuiltInInterfaceAdder.addBuiltInInterfacesToType(this, overrideMap);
56✔
115
        }
116
        this.hasAddedBuiltInInterfaces = true;
127✔
117
    }
118
}
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