renamer: fix trac issue #9778
authorCarlos Tomé <carlostome1990@gmail.com>
Fri, 5 Dec 2014 20:36:55 +0000 (14:36 -0600)
committerAustin Seipp <austin@well-typed.com>
Sat, 6 Dec 2014 00:35:33 +0000 (18:35 -0600)
Summary: Added flag -fwarn-unticked-promoted-constructors

Test Plan: test T9778 under tests/rename/should_compile

Reviewers: jstolarek, simonpj, austin

Reviewed By: jstolarek, simonpj, austin

Subscribers: simonpj, goldfire, jstolarek, thomie, carter

Differential Revision: https://phabricator.haskell.org/D534

GHC Trac Issues: #9778

compiler/main/DynFlags.hs
compiler/rename/RnEnv.hs
docs/users_guide/flags.xml
docs/users_guide/using.xml
testsuite/tests/rename/should_compile/T9778.hs [new file with mode: 0644]
testsuite/tests/rename/should_compile/T9778.stderr [new file with mode: 0644]
testsuite/tests/rename/should_compile/all.T

index aaa52fe..5f277db 100644 (file)
@@ -505,6 +505,7 @@ data WarningFlag =
    | Opt_WarnTypedHoles
    | Opt_WarnPartialTypeSignatures
    | Opt_WarnMissingExportedSigs
+   | Opt_WarnUntickedPromotedConstructors
    deriving (Eq, Show, Enum)
 
 data Language = Haskell98 | Haskell2010
@@ -2835,6 +2836,8 @@ fWarningFlags = [
   flagSpec "warn-unsupported-calling-conventions"
                                          Opt_WarnUnsupportedCallingConventions,
   flagSpec "warn-unsupported-llvm-version"    Opt_WarnUnsupportedLlvmVersion,
+  flagSpec "warn-unticked-promoted-constructors"
+                                         Opt_WarnUntickedPromotedConstructors,
   flagSpec "warn-unused-binds"                Opt_WarnUnusedBinds,
   flagSpec "warn-unused-do-bind"              Opt_WarnUnusedDoBind,
   flagSpec "warn-unused-imports"              Opt_WarnUnusedImports,
index 0cea309..eeffe17 100644 (file)
@@ -699,7 +699,10 @@ lookup_demoted rdr_name
        ; case mb_demoted_name of
            Nothing -> reportUnboundName rdr_name
            Just demoted_name
-             | data_kinds -> return demoted_name
+             | data_kinds ->
+             do { whenWOptM Opt_WarnUntickedPromotedConstructors $
+                  addWarn (untickedPromConstrWarn demoted_name)
+                ; return demoted_name }
              | otherwise  -> unboundNameX WL_Any rdr_name suggest_dk }
 
   | otherwise
@@ -707,6 +710,13 @@ lookup_demoted rdr_name
 
   where
     suggest_dk = ptext (sLit "A data constructor of that name is in scope; did you mean DataKinds?")
+    untickedPromConstrWarn name =
+      text "Unticked promoted constructor" <> colon <+> quotes (ppr name) <> dot
+      $$
+      hsep [ text "Use"
+           , quotes (char '\'' <> ppr name)
+           , text "instead of"
+           , quotes (ppr name) <> dot ]
 
 {-
 Note [Demotion]
index 9ddd271..6ba0c6f 100644 (file)
           </row>
 
           <row>
+            <entry><option>-fwarn-unticked-promoted-constructors</option></entry>
+            <entry>warn if promoted constructors are not ticked </entry>
+            <entry>dynamic</entry>
+            <entry><option>-fno-warn-unticked-promoted-constructors</option></entry>
+          </row>
+
+          <row>
             <entry><option>-fwarn-unused-binds</option></entry>
             <entry>warn about bindings that are unused</entry>
             <entry>dynamic</entry>
index 396af6c..8006fff 100644 (file)
@@ -1796,6 +1796,30 @@ f "2"    = 2
       </varlistentry>
 
       <varlistentry>
+        <term><option>-fwarn-unticked-promoted-constructors</option>:</term>
+        <listitem>
+          <indexterm><primary><option>-fwarn-unticked-promoted-constructors</option></primary></indexterm>
+          <indexterm><primary>promoted constructor, warning</primary></indexterm>
+          <para>Warn if a promoted data constructor is used without a tick preceding it's name.
+          </para>
+          <para>For example:
+          </para>
+<programlisting>
+data Nat = Succ Nat | Zero
+
+data Vec n s where
+  Nil  :: Vec Zero a
+  Cons :: a -> Vec n a -> Vec (Succ n) a
+</programlisting>
+            <para> Will raise two warnings because <function>Zero</function>
+            and <function>Succ</function> are not written as <function>'Zero</function> and
+            <function>'Succ</function>.
+            </para>
+            <para>This warning is off by default.</para>
+        </listitem>
+      </varlistentry>
+
+      <varlistentry>
         <term><option>-fwarn-unused-binds</option>:</term>
         <listitem>
           <indexterm><primary><option>-fwarn-unused-binds</option></primary></indexterm>
diff --git a/testsuite/tests/rename/should_compile/T9778.hs b/testsuite/tests/rename/should_compile/T9778.hs
new file mode 100644 (file)
index 0000000..5b32f67
--- /dev/null
@@ -0,0 +1,8 @@
+{-# LANGUAGE DataKinds #-}
+{-# LANGUAGE GADTs #-}
+module T9778 where
+
+data T = A | B
+
+data G a where
+  C :: G A
diff --git a/testsuite/tests/rename/should_compile/T9778.stderr b/testsuite/tests/rename/should_compile/T9778.stderr
new file mode 100644 (file)
index 0000000..3d2e40f
--- /dev/null
@@ -0,0 +1,3 @@
+ T9778.hs:8:10: Warning:
+     Unticked promoted constructor: ‘A’.
+         Use ‘'A’ instead of ‘A’.
index 7185fba..9265f18 100644 (file)
@@ -218,3 +218,4 @@ test('T7969',
      ['$MAKE -s --no-print-directory T7969'])
 test('T9127', normal, compile, [''])
 test('T4426', normal, compile, [''])
+test('T9778', normal, compile, ['-fwarn-unticked-promoted-constructors'])