Skip to content

Commit 7118aaa

Browse files
Fix bug with notebook variable inheritance
1 parent acccbd6 commit 7118aaa

2 files changed

Lines changed: 17 additions & 2 deletions

File tree

idl/test/client-e2e/notebooks/no-undefined-vars.idlnb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212
{
1313
"type": "code",
1414
"content": [
15-
"print, e.task_names, /implied_print"
15+
"print, e.task_names, /implied_print",
16+
"",
17+
"e"
1618
],
1719
"metadata": {},
1820
"outputs": []

libs/parsing/index/src/lib/helpers/populate-notebook-variables.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ export function PopulateNotebookVariables(
8686
const otherVarName = otherVars[j];
8787

8888
/**
89-
* Inherit variable that we detect
89+
* Inherit variable that we detect being used in our cell
9090
*/
9191
if (otherVarName in ourMain) {
9292
/**
@@ -124,6 +124,16 @@ export function PopulateNotebookVariables(
124124
ourMain[otherVarName].meta.canReset = false;
125125
}
126126
}
127+
/**
128+
* Inherit variable in our cell, but it is not immediately detected
129+
*
130+
* It may still be used with our implied notebook print, however
131+
*
132+
* Example:
133+
*
134+
* Cell 1: "arr = [1,2,3]""
135+
* Cell 2: "arr" <- implied print as variable arr
136+
*/
127137
} else {
128138
// copy
129139
ourMain[otherVarName] = copy(otherMain[otherVarName]);
@@ -137,6 +147,9 @@ export function PopulateNotebookVariables(
137147
// update location
138148
ourMain[otherVarName].file = files[i];
139149
ourMain[otherVarName].filePos = otherMain[otherVarName].pos;
150+
151+
// dont allow resetting the variable because it is not defined in our cell
152+
ourMain[otherVarName].meta.canReset = false;
140153
}
141154
}
142155
}

0 commit comments

Comments
 (0)