Skip to content

Commit ac55e5f

Browse files
authored
Make Invalid compatible with typed arrays (#1596)
2 parents 2f3df88 + e0f3bc9 commit ac55e5f

2 files changed

Lines changed: 41 additions & 1 deletion

File tree

src/bscPlugin/validation/ScopeValidator.spec.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1832,6 +1832,22 @@ describe('ScopeValidator', () => {
18321832
});
18331833
});
18341834

1835+
it('allows using invalid as argument for typed array params', () => {
1836+
program.setFile<BrsFile>('source/main.bs', `
1837+
sub takesIntArray(arr as integer[])
1838+
end sub
1839+
1840+
sub takesStrArray(arr as string[])
1841+
end sub
1842+
1843+
sub test()
1844+
takesIntArray(invalid)
1845+
takesStrArray(invalid)
1846+
end sub
1847+
`);
1848+
program.validate();
1849+
expectZeroDiagnostics(program);
1850+
});
18351851
});
18361852

18371853
describe('cannotFindName', () => {
@@ -2962,6 +2978,17 @@ describe('ScopeValidator', () => {
29622978
spy.getCalls().map(x => (x.args?.[0] as string)?.toString()).filter(x => x?.includes('Error when calling plugin'))
29632979
).to.eql([]);
29642980
});
2981+
2982+
it('allows returning invalid instead of typed array', () => {
2983+
program.setFile<BrsFile>('source/main.bs', `
2984+
function getNumbers() as integer[]
2985+
return invalid
2986+
end function
2987+
`);
2988+
program.validate();
2989+
expectZeroDiagnostics(program);
2990+
});
2991+
29652992
});
29662993

29672994
describe('returnTypeCoercionMismatch', () => {
@@ -3430,6 +3457,17 @@ describe('ScopeValidator', () => {
34303457
]);
34313458
});
34323459
});
3460+
3461+
it('allows assigning invalid to typed arrays', () => {
3462+
program.setFile<BrsFile>('source/main.bs', `
3463+
sub test()
3464+
intArray as integer[] = invalid
3465+
strArray as string[] = invalid
3466+
end sub
3467+
`);
3468+
program.validate();
3469+
expectZeroDiagnostics(program);
3470+
});
34333471
});
34343472

34353473
describe('operatorTypeMismatch', () => {

src/types/ArrayType.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

22
import { SymbolTypeFlag } from '../SymbolTypeFlag';
3-
import { isArrayType, isDynamicType, isEnumMemberType, isObjectType } from '../astUtils/reflection';
3+
import { isArrayType, isDynamicType, isEnumMemberType, isInvalidType, isObjectType } from '../astUtils/reflection';
44
import type { TypeCompatibilityData } from '../interfaces';
55
import { BscType } from './BscType';
66
import { BscTypeKind } from './BscTypeKind';
@@ -53,6 +53,8 @@ export class ArrayType extends BscType {
5353
return true;
5454
} else if (isObjectType(targetType)) {
5555
return true;
56+
} else if (isInvalidType(targetType)) {
57+
return true;
5658
} else if (isUnionTypeCompatible(this, targetType)) {
5759
return true;
5860
} else if (isArrayType(targetType)) {

0 commit comments

Comments
 (0)