@@ -365,6 +365,67 @@ public void readdingMovedFileWithSameContentUpdatesModel() throws IOException {
365365 assertNotNull (manager .getCompilationUnit (fileTest ), "file should be present after re-adding same contents" );
366366 }
367367
368+ @ Test
369+ public void replacingCompilationUnitClearsOldLookupCacheKeys () throws IOException {
370+ GlobalCaches .clearAll ();
371+ File projectFolder = new File ("./temp/testProject_replace_clears_lookup_cache/" );
372+ File wurstFolder = new File (projectFolder , "wurst" );
373+ newCleanFolder (wurstFolder );
374+
375+ WFile fileMain = WFile .create (new File (wurstFolder , "Main.wurst" ));
376+ WFile fileWurst = WFile .create (new File (wurstFolder , "Wurst.wurst" ));
377+ writeFile (fileMain , string (
378+ "package Main" ,
379+ "public function foo()"
380+ ));
381+ writeFile (fileWurst , "package Wurst\n " );
382+
383+ ModelManagerImpl manager = new ModelManagerImpl (projectFolder , new BufferManager ());
384+ manager .buildProject ();
385+ CompilationUnit oldCu = manager .getCompilationUnit (fileMain );
386+ assertNotNull (oldCu );
387+
388+ GlobalCaches .CacheKey oldKey = new GlobalCaches .CacheKey (oldCu , "foo" , GlobalCaches .LookupType .FUNC );
389+ GlobalCaches .lookupCache .put (oldKey , oldCu );
390+
391+ manager .syncCompilationUnitContent (fileMain , string (
392+ "package Main" ,
393+ "public function bar()"
394+ ));
395+
396+ assertEquals (GlobalCaches .lookupCache .containsKey (oldKey ), false ,
397+ "replacing a CU must drop lookup keys that keep the old AST alive" );
398+ }
399+
400+ @ Test
401+ public void removingCompilationUnitClearsOldLookupCacheKeys () throws IOException {
402+ GlobalCaches .clearAll ();
403+ File projectFolder = new File ("./temp/testProject_remove_clears_lookup_cache/" );
404+ File wurstFolder = new File (projectFolder , "wurst" );
405+ newCleanFolder (wurstFolder );
406+
407+ WFile fileMain = WFile .create (new File (wurstFolder , "Main.wurst" ));
408+ WFile fileWurst = WFile .create (new File (wurstFolder , "Wurst.wurst" ));
409+ writeFile (fileMain , string (
410+ "package Main" ,
411+ "public function foo()"
412+ ));
413+ writeFile (fileWurst , "package Wurst\n " );
414+
415+ ModelManagerImpl manager = new ModelManagerImpl (projectFolder , new BufferManager ());
416+ manager .buildProject ();
417+ CompilationUnit oldCu = manager .getCompilationUnit (fileMain );
418+ assertNotNull (oldCu );
419+
420+ GlobalCaches .CacheKey oldKey = new GlobalCaches .CacheKey (oldCu , "foo" , GlobalCaches .LookupType .FUNC );
421+ GlobalCaches .lookupCache .put (oldKey , oldCu );
422+
423+ manager .removeCompilationUnit (fileMain );
424+
425+ assertEquals (GlobalCaches .lookupCache .containsKey (oldKey ), false ,
426+ "removing a CU must drop lookup keys that keep the old AST alive" );
427+ }
428+
368429 @ Test
369430 public void duplicatePackageReportsSingleClearMessage () throws IOException {
370431 File projectFolder = new File ("./temp/testProject_duplicate_package_message/" );
0 commit comments