@@ -50435,21 +50435,24 @@ function validateUseMemo(fn) {
5043550435    return errors.asResult();
5043650436}
5043750437function validateNoContextVariableAssignment(fn, errors) {
50438+     const context = new Set(fn.context.map(place => place.identifier.id));
5043850439    for (const block of fn.body.blocks.values()) {
5043950440        for (const instr of block.instructions) {
5044050441            const value = instr.value;
5044150442            switch (value.kind) {
5044250443                case 'StoreContext': {
50443-                     errors.pushDiagnostic(CompilerDiagnostic.create({
50444-                         category: ErrorCategory.UseMemo,
50445-                         reason: 'useMemo() callbacks may not reassign variables declared outside of the callback',
50446-                         description: 'useMemo() callbacks must be pure functions and cannot reassign variables defined outside of the callback function',
50447-                         suggestions: null,
50448-                     }).withDetails({
50449-                         kind: 'error',
50450-                         loc: value.lvalue.place.loc,
50451-                         message: 'Cannot reassign variable',
50452-                     }));
50444+                     if (context.has(value.lvalue.place.identifier.id)) {
50445+                         errors.pushDiagnostic(CompilerDiagnostic.create({
50446+                             category: ErrorCategory.UseMemo,
50447+                             reason: 'useMemo() callbacks may not reassign variables declared outside of the callback',
50448+                             description: 'useMemo() callbacks must be pure functions and cannot reassign variables defined outside of the callback function',
50449+                             suggestions: null,
50450+                         }).withDetails({
50451+                             kind: 'error',
50452+                             loc: value.lvalue.place.loc,
50453+                             message: 'Cannot reassign variable',
50454+                         }));
50455+                     }
5045350456                    break;
5045450457                }
5045550458            }
0 commit comments