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

rokucommunity / brighterscript / #13067

25 Sep 2024 03:14PM UTC coverage: 86.525% (-1.4%) from 87.933%
#13067

push

web-flow
Merge f1fe33c6d into 56dcaaa63

10903 of 13389 branches covered (81.43%)

Branch coverage included in aggregate %.

6936 of 7533 new or added lines in 100 files covered. (92.07%)

83 existing lines in 18 files now uncovered.

12548 of 13714 relevant lines covered (91.5%)

27591.0 hits per line

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

86.59
/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();
142,274✔
17
        this.innerTypes = innerTypes;
142,274✔
18
    }
19

20
    public readonly kind = BscTypeKind.ArrayType;
142,274✔
21

22
    public innerTypes: BscType[] = [];
142,274✔
23

24
    public get defaultType(): BscType {
25
        if (this.innerTypes?.length === 0) {
3,526!
26
            return DynamicType.instance;
3,210✔
27
        } else if (this.innerTypes?.length === 1) {
316!
28
            return this.innerTypes[0];
285✔
29
        }
30
        return getUniqueType(this.innerTypes, unionTypeFactory);
31✔
31
    }
32

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

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

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

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

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

77
    addBuiltInInterfaces() {
78
        if (!this.hasAddedBuiltInInterfaces) {
96✔
79
            const overrideMap = new Map<string, BuiltInInterfaceOverride>();
17✔
80
            const defaultType = this.defaultType;
17✔
81
            overrideMap
17✔
82
                // ifArray
83
                .set('peek', { returnType: defaultType })
84
                .set('pop', { returnType: defaultType })
85
                .set('push', { parameterTypes: [defaultType] })
86
                .set('shift', { returnType: defaultType })
87
                .set('unshift', { parameterTypes: [defaultType] })
88
                .set('append', { parameterTypes: [this] })
89
                // ifArrayGet
90
                .set('get', { returnType: defaultType })
91
                // ifArraySet
92
                .set('get', { parameterTypes: [IntegerType.instance, defaultType] })
93
                //ifEnum
94
                .set('next', { returnType: defaultType });
95
            BuiltInInterfaceAdder.addBuiltInInterfacesToType(this, overrideMap);
17✔
96
        }
97
        this.hasAddedBuiltInInterfaces = true;
96✔
98
    }
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