Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: wrong"assignment/nothing-assigned" error if RHS calls expression lambda #781

Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
isSdsCallable,
isSdsClass,
isSdsEnumVariant,
isSdsExpressionLambda,
isSdsNamedType,
isSdsParameter,
isSdsReference,
Expand Down Expand Up @@ -121,6 +122,15 @@ export class SafeDsNodeMapper {
}
}

// If the RHS calls an expression lambda, the first assignee gets its result
if (isSdsExpressionLambda(callable)) {
if (assigneePosition === 0) {
return callable.result;
} else {
return undefined;
}
}

// Otherwise, the assignee gets the result at the same position
const abstractResults = getAbstractResults(callable);
return abstractResults[assigneePosition];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,18 @@ describe('SafeDsNodeMapper', () => {
`,
expected: ['r1', 'r2'],
},
{
name: 'expression lambda',
code: `
segment mySegment() {
val f = () -> 1;

val a, val b = f();
};
`,
expected: ['1', undefined],
index: 1,
},
{
name: 'function (one result)',
code: `
Expand Down Expand Up @@ -179,10 +191,12 @@ describe('SafeDsNodeMapper', () => {

const abstractResultNameOrNull = (node: SdsAssignee): string | undefined => {
const assignedObject = nodeMapper.assigneeToAssignedObject(node);
if (isSdsAbstractResult(assignedObject)) {
if (!assignedObject) {
return undefined;
} else if (isSdsAbstractResult(assignedObject)) {
return assignedObject.name;
} else {
return undefined;
return assignedObject.$cstNode?.text;
}
};
});
Expand Down