diff --git a/pystencils/cpu/cpujit.py b/pystencils/cpu/cpujit.py
index ccaeb0cee600a807cb3d73704e67aff14ff1dcf4..4ac13a0656d3771a67f51ef627386986d5059428 100644
--- a/pystencils/cpu/cpujit.py
+++ b/pystencils/cpu/cpujit.py
@@ -535,6 +535,7 @@ class ExtensionModuleCode:
         self._code_string += create_module_boilerplate_code(self._code_hash, self._function_names)
 
     def get_hash_of_code(self):
+        assert self._code_string, "The code must be generated first"
         return self._code_hash
 
     def write_to_file(self, file):