Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Added test
  • Loading branch information
markwpearce committed Mar 19, 2026
commit 424f2223a3d40c75470c80917db45dbe25402ed4
47 changes: 47 additions & 0 deletions src/bscPlugin/validation/ScopeValidator.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4442,6 +4442,53 @@ describe('ScopeValidator', () => {
DiagnosticMessages.assignmentTypeMismatch('string', 'integer').message
]);
});

it('allows assignment of for each loop variable as string for union of AAs and string array', () => {
program.setFile('source/main.bs', `
sub main(data as roAssociativeArray or string[])
for each item as string in data
print item
end for
end sub
`);
program.validate();
expectZeroDiagnostics(program);
});

it('allows assignment of for each loop variable from array of type statement types of union of custom components', () => {

program.setFile('components/widget1.xml', trim`
<?xml version="1.0" encoding="utf-8" ?>
<component name="Widget1" extends="Group">
<interface>
<field id="someField" type="string" />
</interface>
</component>
`);

program.setFile('components/widget2.xml', trim`
<?xml version="1.0" encoding="utf-8" ?>
<component name="Widget2" extends="Group">
<interface>
<field id="someField" type="integer" />
</interface>
</component>
`);


program.setFile('source/main.bs', `
sub main(data as thing[])
for each item in data
print item.someField
end for
end sub


type thing = roSGNodeWidget1 or roSGNodeWidget2
`);
program.validate();
expectZeroDiagnostics(program);
});
});
});

Expand Down
4 changes: 2 additions & 2 deletions src/bscPlugin/validation/ScopeValidator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1453,10 +1453,10 @@ export class ScopeValidator {
}

const loopType = forEachStmt.getLoopVariableType({ flags: SymbolTypeFlag.runtime, statementIndex: forEachStmt.statementIndex });
if (loopType?.isResolvable()) {
if (forEachStmt.typeExpression && loopType?.isResolvable()) {

const data: TypeCompatibilityData = {};
if (!loopType.isTypeCompatible(targetItemType, data)) {
if (!loopType.isTypeCompatible(targetItemType, data)) { //{) {
this.addMultiScopeDiagnostic({
...DiagnosticMessages.assignmentTypeMismatch(targetItemType.toString(), loopType.toString(), data),
location: forEachStmt.typeExpression.location
Expand Down
Loading