diff --git a/compiler/Language/Haskell/Syntax/Module/Name.hs b/compiler/Language/Haskell/Syntax/Module/Name.hs
index 65e64d8700fbaa4efd4ac1172a56b892b9949078..89ea910b29d19bb869373e793a8ad0a51cb19cda 100644
--- a/compiler/Language/Haskell/Syntax/Module/Name.hs
+++ b/compiler/Language/Haskell/Syntax/Module/Name.hs
@@ -56,5 +56,5 @@ moduleNameColons = dots_to_colons . moduleNameString
 
 parseModuleName :: Parse.ReadP ModuleName
 parseModuleName = fmap mkModuleName
-                $ Parse.munch1 (\c -> isAlphaNum c || c `elem` "_.")
+                $ Parse.munch1 (\c -> isAlphaNum c || c `elem` "_.'")
 
diff --git a/testsuite/tests/rename/should_compile/T24732.hs b/testsuite/tests/rename/should_compile/T24732.hs
new file mode 100644
index 0000000000000000000000000000000000000000..0cf7e6d73d86fcb55379542cc6ea7711921ca782
--- /dev/null
+++ b/testsuite/tests/rename/should_compile/T24732.hs
@@ -0,0 +1,4 @@
+import P'
+
+main :: IO ()
+main = printf "Hello World\n"
\ No newline at end of file
diff --git a/testsuite/tests/rename/should_compile/T24732.stdout b/testsuite/tests/rename/should_compile/T24732.stdout
new file mode 100644
index 0000000000000000000000000000000000000000..557db03de997c86a4a028e1ebd3a1ceb225be238
--- /dev/null
+++ b/testsuite/tests/rename/should_compile/T24732.stdout
@@ -0,0 +1 @@
+Hello World
diff --git a/testsuite/tests/rename/should_compile/all.T b/testsuite/tests/rename/should_compile/all.T
index f5d7fe904790b99687366fd49022ae9abf0c6cba..745335949bb21d19950fbfe844a9b40b68af1eb7 100644
--- a/testsuite/tests/rename/should_compile/all.T
+++ b/testsuite/tests/rename/should_compile/all.T
@@ -223,3 +223,4 @@ test('T22478a', req_th, compile, [''])
 test('RecordWildCardDeprecation', normal, multimod_compile, ['RecordWildCardDeprecation', '-Wno-duplicate-exports'])
 test('T14032b', normal, compile_and_run, [''])
 test('T14032d', normal, compile, [''])
+test('T24732', normal, compile_and_run, ['-package "base(Prelude, Text.Printf as P\')"'])