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

rokucommunity / brighterscript / #13342

25 Nov 2024 08:44PM UTC coverage: 89.053% (+2.2%) from 86.874%
#13342

push

web-flow
Merge 961502182 into c5674f5d8

7359 of 8712 branches covered (84.47%)

Branch coverage included in aggregate %.

55 of 64 new or added lines in 9 files covered. (85.94%)

544 existing lines in 54 files now uncovered.

9724 of 10471 relevant lines covered (92.87%)

1825.46 hits per line

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

75.86
/src/types/FunctionType.ts
1
import type { BscType } from './BscType';
2
import { DynamicType } from './DynamicType';
1✔
3

4
export class FunctionType implements BscType {
1✔
5
    constructor(
6
        public returnType: BscType
2,879✔
7
    ) {
8

9
    }
10

11
    /**
12
     * The name of the function for this type. Can be undefined
13
     */
14
    public name: string | undefined;
15

16
    /**
17
     * Determines if this is a sub or not
18
     */
19
    public isSub = false;
2,879✔
20

21
    public params = [] as Array<{ name: string; type: BscType; isOptional: boolean }>;
2,879✔
22

23
    public setName(name: string) {
24
        this.name = name;
2,851✔
25
        return this;
2,851✔
26
    }
27

28
    public addParameter(name: string, type: BscType, isOptional: boolean) {
29
        this.params.push({
1,181✔
30
            name: name,
31
            type: type,
32
            isOptional: isOptional === true ? true : false
1,181✔
33
        });
34
        return this;
1,181✔
35
    }
36

37
    public isAssignableTo(targetType: BscType) {
38
        if (targetType instanceof DynamicType) {
5✔
39
            return true;
1✔
40
        } else if (targetType instanceof FunctionType) {
4!
41
            //compare all parameters
42
            let len = Math.max(this.params.length, targetType.params.length);
4✔
43
            for (let i = 0; i < len; i++) {
4✔
44
                let myParam = this.params[i];
2✔
45
                let targetParam = targetType.params[i];
2✔
46
                if (!myParam || !targetParam || !myParam.type.isAssignableTo(targetParam.type)) {
2!
47
                    return false;
2✔
48
                }
49
            }
50

51
            //compare return type
52
            if (!this.returnType || !targetType.returnType || !this.returnType.isAssignableTo(targetType.returnType)) {
2✔
53
                return false;
1✔
54
            }
55

56
            //made it here, all params and return type are equivalent
57
            return true;
1✔
58
        } else {
UNCOV
59
            return false;
×
60
        }
61
    }
62

63
    public isConvertibleTo(targetType: BscType) {
UNCOV
64
        return this.isAssignableTo(targetType);
×
65
    }
66

67
    public toString() {
68
        let paramTexts: string[] = [];
18✔
69
        for (let param of this.params) {
18✔
70
            paramTexts.push(`${param.name}${param.isOptional ? '?' : ''} as ${param.type.toString()}`);
16✔
71
        }
72
        return `${this.isSub ? 'sub' : 'function'} ${this.name}(${paramTexts.join(', ')}) as ${this.returnType.toString()}`;
18✔
73

74
    }
75

76
    public toTypeString(): string {
77
        return 'Function';
1✔
78
    }
79

80
    public clone() {
UNCOV
81
        const result = new FunctionType(this.returnType);
×
UNCOV
82
        for (let param of this.params) {
×
UNCOV
83
            result.addParameter(param.name, param.type, param.isOptional);
×
84
        }
UNCOV
85
        result.isSub = this.isSub;
×
UNCOV
86
        result.returnType = this.returnType?.clone();
×
UNCOV
87
        return result;
×
88
    }
89
}
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