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

rokucommunity / brighterscript / #15903

11 May 2026 06:41PM UTC coverage: 86.896% (-2.2%) from 89.094%
#15903

push

web-flow
Merge 70dfd6181 into ce68f5cb7

15597 of 18958 branches covered (82.27%)

Branch coverage included in aggregate %.

9 of 9 new or added lines in 3 files covered. (100.0%)

955 existing lines in 53 files now uncovered.

16351 of 17808 relevant lines covered (91.82%)

27326.16 hits per line

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

92.04
/src/types/ArrayType.ts
1

2
import { SymbolTypeFlag } from '../SymbolTypeFlag';
1✔
3
import { isArrayType, isDynamicType, isEnumMemberType, isInvalidType, isObjectType, isTypeStatementType } 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();
226,166✔
18
        this.innerTypes = innerTypes;
226,166✔
19
    }
20

21
    public readonly kind = BscTypeKind.ArrayType;
226,166✔
22
    public isBuiltIn = true;
226,166✔
23

24
    public innerTypes: BscType[] = [];
226,166✔
25

26
    public _defaultType: BscType;
27
    private isCheckingInnerTypesForDefaultType = false;
226,166✔
28

29
    public get defaultType(): BscType {
30
        if (this._defaultType) {
12,425✔
31
            return this._defaultType;
2,079✔
32
        }
33
        if (this.innerTypes?.length === 0 || this.isCheckingInnerTypesForDefaultType) {
10,346!
34
            return DynamicType.instance;
10,052✔
35
        }
36
        this.isCheckingInnerTypesForDefaultType = true;
294✔
37

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

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

75
    public toString() {
76
        return `Array<${this.defaultType.toString()}>`;
10,688✔
77
    }
78

79
    public toTypeString(): string {
80
        //typed arrays have no first-class representation in BrightScript; collapse to
81
        //`dynamic` at transpile so the runtime accepts arbitrary array values.
82
        return 'dynamic';
7✔
83
    }
84

85
    public isEqual(targetType: BscType): boolean {
86
        if (isArrayType(targetType)) {
21✔
87
            if (targetType.innerTypes.length !== this.innerTypes.length) {
18!
UNCOV
88
                return false;
×
89
            }
90
            for (let i = 0; i < this.innerTypes.length; i++) {
18✔
91
                if (!this.innerTypes[i].isEqual(targetType.innerTypes[i])) {
17✔
92
                    return false;
8✔
93
                }
94
            }
95
            return true;
10✔
96
        }
97
        return false;
3✔
98
    }
99

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

© 2026 Coveralls, Inc