Skip to content
This repository was archived by the owner on Apr 14, 2022. It is now read-only.

Commit b828161

Browse files
authored
More null checks in NotifyAnalysisBegins (#973)
* More null checks in NotifyAnalysisBegins * cleanup * add todo for later * drop unneeded empty enumerable
1 parent fe1f0af commit b828161

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

src/Analysis/Ast/Impl/Modules/PythonModule.cs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -406,15 +406,20 @@ public void NotifyAnalysisBegins() {
406406
// In all variables find those imported, then traverse imported modules
407407
// and remove references to this module. If variable refers to a module,
408408
// recurse into module but only process global scope.
409+
410+
if (GlobalScope == null) {
411+
return;
412+
}
413+
414+
// TODO: Figure out where the nulls below are coming from.
409415
var importedVariables = ((IScope)GlobalScope)
410-
.TraverseDepthFirst(c => c.Children)
411-
.ExcludeDefault()
412-
.SelectMany(s => s.Variables)
413-
.Where(v => v.Source == VariableSource.Import);
416+
.TraverseDepthFirst(c => c?.Children ?? Enumerable.Empty<IScope>())
417+
.SelectMany(s => s?.Variables ?? VariableCollection.Empty)
418+
.Where(v => v?.Source == VariableSource.Import);
414419

415420
foreach (var v in importedVariables) {
416421
v.RemoveReferences(this);
417-
if(v.Value is IPythonModule module) {
422+
if (v.Value is IPythonModule module) {
418423
RemoveReferencesInModule(module);
419424
}
420425
}

0 commit comments

Comments
 (0)