Commit 87160c1a authored by carlostome's avatar carlostome Committed by Austin Seipp

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
parent 9a101074
......@@ -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,
......
......@@ -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]
......
......@@ -1569,6 +1569,13 @@
<entry><option>-fno-warn-unrecognised-pragmas</option></entry>
</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>
......
......@@ -1795,6 +1795,30 @@ f "2" = 2
</listitem>
</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>
......
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE GADTs #-}
module T9778 where
data T = A | B
data G a where
C :: G A
T9778.hs:8:10: Warning:
Unticked promoted constructor: ‘A’.
Use ‘'A’ instead of ‘A’.
......@@ -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'])
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment