[commit: ghc] master: renamer: fix trac issue #9778 (87160c1)
git at git.haskell.org
git at git.haskell.org
Sat Dec 6 00:35:44 UTC 2014
Repository : ssh://git@git.haskell.org/ghc
On branch : master
Link : http://ghc.haskell.org/trac/ghc/changeset/87160c1a5e5c742de176b29d8c3a596fba0983cf/ghc
>---------------------------------------------------------------
commit 87160c1a5e5c742de176b29d8c3a596fba0983cf
Author: Carlos Tomé <carlostome1990 at gmail.com>
Date: Fri Dec 5 14:36:55 2014 -0600
renamer: fix trac issue #9778
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
>---------------------------------------------------------------
87160c1a5e5c742de176b29d8c3a596fba0983cf
compiler/main/DynFlags.hs | 3 +++
compiler/rename/RnEnv.hs | 12 ++++++++++-
docs/users_guide/flags.xml | 7 +++++++
docs/users_guide/using.xml | 24 ++++++++++++++++++++++
testsuite/tests/rename/should_compile/T9778.hs | 8 ++++++++
testsuite/tests/rename/should_compile/T9778.stderr | 3 +++
testsuite/tests/rename/should_compile/all.T | 1 +
7 files changed, 57 insertions(+), 1 deletion(-)
diff --git a/compiler/main/DynFlags.hs b/compiler/main/DynFlags.hs
index aaa52fe..5f277db 100644
--- a/compiler/main/DynFlags.hs
+++ b/compiler/main/DynFlags.hs
@@ -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,
diff --git a/compiler/rename/RnEnv.hs b/compiler/rename/RnEnv.hs
index 0cea309..eeffe17 100644
--- a/compiler/rename/RnEnv.hs
+++ b/compiler/rename/RnEnv.hs
@@ -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]
diff --git a/docs/users_guide/flags.xml b/docs/users_guide/flags.xml
index 9ddd271..6ba0c6f 100644
--- a/docs/users_guide/flags.xml
+++ b/docs/users_guide/flags.xml
@@ -1570,6 +1570,13 @@
</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>
diff --git a/docs/users_guide/using.xml b/docs/users_guide/using.xml
index 396af6c..8006fff 100644
--- a/docs/users_guide/using.xml
+++ b/docs/users_guide/using.xml
@@ -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
index 0000000..5b32f67
--- /dev/null
+++ b/testsuite/tests/rename/should_compile/T9778.hs
@@ -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
index 0000000..3d2e40f
--- /dev/null
+++ b/testsuite/tests/rename/should_compile/T9778.stderr
@@ -0,0 +1,3 @@
+ T9778.hs:8:10: Warning:
+ Unticked promoted constructor: ‘A’.
+ Use ‘'A’ instead of ‘A’.
diff --git a/testsuite/tests/rename/should_compile/all.T b/testsuite/tests/rename/should_compile/all.T
index 7185fba..9265f18 100644
--- a/testsuite/tests/rename/should_compile/all.T
+++ b/testsuite/tests/rename/should_compile/all.T
@@ -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'])
More information about the ghc-commits
mailing list