diff --git a/src/lpython/semantics/python_ast_to_asr.cpp b/src/lpython/semantics/python_ast_to_asr.cpp index 2968f70770..f7fdfa839b 100644 --- a/src/lpython/semantics/python_ast_to_asr.cpp +++ b/src/lpython/semantics/python_ast_to_asr.cpp @@ -6731,6 +6731,16 @@ Result python_ast_to_asr(Allocator &al, LocationManager throw LCompilersException("Verify failed"); }; #endif + if (compiler_options.disable_main) { + // TODO: the main program should have not been created, but sometimes + // it is, so we explicitly remove it here. + for (auto &item : tu->m_global_scope->get_scope()) { + if (ASR::is_a(*item.second)) { + tu->m_global_scope->erase_symbol(item.first); + break; + } + } + } } return tu;