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

rokucommunity / brighterscript / #14044

20 Mar 2025 07:09PM UTC coverage: 87.163% (-2.0%) from 89.117%
#14044

push

web-flow
Merge e33b1f944 into 0eceb0830

13257 of 16072 branches covered (82.49%)

Branch coverage included in aggregate %.

1163 of 1279 new or added lines in 24 files covered. (90.93%)

802 existing lines in 52 files now uncovered.

14323 of 15570 relevant lines covered (91.99%)

21312.85 hits per line

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

87.85
/src/types/ArrayType.ts
1

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

21
    public readonly kind = BscTypeKind.ArrayType;
174,642✔
22
    public isBuiltIn = true;
174,642✔
23

24
    public innerTypes: BscType[] = [];
174,642✔
25

26
    public _defaultType: BscType;
27
    private isCheckingInnerTypesForDefaultType = false;
174,642✔
28

29
    public get defaultType(): BscType {
30
        if (this._defaultType) {
8,725✔
31
            return this._defaultType;
4,635✔
32
        }
33
        if (this.innerTypes?.length === 0 || this.isCheckingInnerTypesForDefaultType) {
4,090!
34
            return DynamicType.instance;
3,894✔
35
        }
36
        this.isCheckingInnerTypesForDefaultType = true;
196✔
37

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

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

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

71
    public toString() {
72
        return `Array<${this.defaultType.toString()}>`;
4,095✔
73
    }
74

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

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

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