From e0f3bc95e9f37ba5e2d83657ac622fb857219178 Mon Sep 17 00:00:00 2001 From: Mark Pearce Date: Sun, 23 Nov 2025 07:30:32 -0400 Subject: [PATCH] ALlows assigning invalid to a typed array --- .../validation/ScopeValidator.spec.ts | 38 +++++++++++++++++++ src/types/ArrayType.ts | 4 +- 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/src/bscPlugin/validation/ScopeValidator.spec.ts b/src/bscPlugin/validation/ScopeValidator.spec.ts index 79646e87a..051ff5ca7 100644 --- a/src/bscPlugin/validation/ScopeValidator.spec.ts +++ b/src/bscPlugin/validation/ScopeValidator.spec.ts @@ -1832,6 +1832,22 @@ describe('ScopeValidator', () => { }); }); + it('allows using invalid as argument for typed array params', () => { + program.setFile('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', () => { @@ -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('source/main.bs', ` + function getNumbers() as integer[] + return invalid + end function + `); + program.validate(); + expectZeroDiagnostics(program); + }); + }); describe('returnTypeCoercionMismatch', () => { @@ -3430,6 +3457,17 @@ describe('ScopeValidator', () => { ]); }); }); + + it('allows assigning invalid to typed arrays', () => { + program.setFile('source/main.bs', ` + sub test() + intArray as integer[] = invalid + strArray as string[] = invalid + end sub + `); + program.validate(); + expectZeroDiagnostics(program); + }); }); describe('operatorTypeMismatch', () => { diff --git a/src/types/ArrayType.ts b/src/types/ArrayType.ts index ce315c65e..5eb50029a 100644 --- a/src/types/ArrayType.ts +++ b/src/types/ArrayType.ts @@ -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'; @@ -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)) {