Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions src/bscPlugin/validation/ScopeValidator.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1832,6 +1832,22 @@ describe('ScopeValidator', () => {
});
});

it('allows using invalid as argument for typed array params', () => {
program.setFile<BrsFile>('source/main.bs', `
sub takesIntArray(arr as integer[])
end sub

sub takesStrArray(arr as string[])
end sub

sub test()
takesIntArray(invalid)
takesStrArray(invalid)
end sub
`);
program.validate();
expectZeroDiagnostics(program);
});
});

describe('cannotFindName', () => {
Expand Down Expand Up @@ -2962,6 +2978,17 @@ describe('ScopeValidator', () => {
spy.getCalls().map(x => (x.args?.[0] as string)?.toString()).filter(x => x?.includes('Error when calling plugin'))
).to.eql([]);
});

it('allows returning invalid instead of typed array', () => {
program.setFile<BrsFile>('source/main.bs', `
function getNumbers() as integer[]
return invalid
end function
`);
program.validate();
expectZeroDiagnostics(program);
});

});

describe('returnTypeCoercionMismatch', () => {
Expand Down Expand Up @@ -3430,6 +3457,17 @@ describe('ScopeValidator', () => {
]);
});
});

it('allows assigning invalid to typed arrays', () => {
program.setFile<BrsFile>('source/main.bs', `
sub test()
intArray as integer[] = invalid
strArray as string[] = invalid
end sub
`);
program.validate();
expectZeroDiagnostics(program);
});
});

describe('operatorTypeMismatch', () => {
Expand Down
4 changes: 3 additions & 1 deletion src/types/ArrayType.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

import { SymbolTypeFlag } from '../SymbolTypeFlag';
import { isArrayType, isDynamicType, isEnumMemberType, isObjectType } from '../astUtils/reflection';
import { isArrayType, isDynamicType, isEnumMemberType, isInvalidType, isObjectType } from '../astUtils/reflection';
import type { TypeCompatibilityData } from '../interfaces';
import { BscType } from './BscType';
import { BscTypeKind } from './BscTypeKind';
Expand Down Expand Up @@ -53,6 +53,8 @@ export class ArrayType extends BscType {
return true;
} else if (isObjectType(targetType)) {
return true;
} else if (isInvalidType(targetType)) {
return true;
} else if (isUnionTypeCompatible(this, targetType)) {
return true;
} else if (isArrayType(targetType)) {
Expand Down