Consider the following code:
x = 1;
nb = NotebookPut@Notebook[
{
Cell[
BoxData@ToBoxes@Defer@{$Context, x = 2},
"Input",
CellContext -> Notebook
]
}
];
NotebookEvaluate[nb, InsertResults -> True];
This code first creates Global`x, then it creates a notebook with a cell with CellContext->Notebook. Evaluating the notebook using NotebookEvaluate creates the symbol Notebook$$…`x, everything works as expected.
But now, let's replace the last line with the following:
Block[{$ContextPath = $ContextPath},
NotebookEvaluate[nb, InsertResults -> True];
]
Rerunning the code (including the creation of the notebook), now issues a shadowing warning for x.
Why is this happening? This seems to be a rather strange effect of Block...
Blockwith$ContextPathcauses all sorts of weird shadowing messages where they shouldn't be. I've reported a few cases of this as bugs but my guess is WRI doesn't care about such a minor/cosmetic one when they've got so many other bugs to quash. – b3m2a1 Feb 13 '19 at 22:22NotebookEvaluatedoes not cope well withCellContext->Notebook: 135025 – Kuba Feb 13 '19 at 22:28$ContextPathstack creation mechanism or like the way it reads that stack or something. – b3m2a1 Feb 13 '19 at 22:32NotebookEvaluteso I'll have to live with all its quirks...Regarding the dialog subsession: why would you expect the first example to also produce a warning? In terms of documentation, there is a least some information in the doc page ofDialogand the "Dialogs" tutorial, but nothing too specific. – Lukas Lang Feb 13 '19 at 22:48CellContext->Notebookin context ofNotebookEvaluateworking likeBeginorBeginPackage? My point was that there are many not really precisely defined actions so who knows what really should happen. But yes, it is clearly unexpected. – Kuba Feb 13 '19 at 22:53