[project @ 2004-10-18 18:24:59 by igloo]
authorigloo <unknown>
Mon, 18 Oct 2004 18:25:06 +0000 (18:25 +0000)
committerigloo <unknown>
Mon, 18 Oct 2004 18:25:06 +0000 (18:25 +0000)
Implement -fwarn-incomplete-record-updates

ghc/compiler/deSugar/Match.lhs
ghc/compiler/main/CmdLineOpts.lhs
ghc/compiler/main/DriverFlags.hs
ghc/docs/users_guide/flags.xml
ghc/docs/users_guide/using.xml

index 7626360..ebe503a 100644 (file)
@@ -67,8 +67,12 @@ matchCheck_really dflags ctx vars ty qs
   | otherwise             =
       match vars ty qs
   where (pats, eqns_shadow) = check qs
-        incomplete    = dopt Opt_WarnIncompletePatterns dflags
-                       && (notNull pats)
+        incomplete    = want_incomplete && (notNull pats)
+        want_incomplete = case ctx of
+                              DsMatchContext RecUpd _ _ ->
+                                  dopt Opt_WarnIncompletePatternsRecUpd dflags
+                              _ ->
+                                  dopt Opt_WarnIncompletePatterns       dflags
         shadow        = dopt Opt_WarnOverlappingPatterns dflags
                        && not (null eqns_shadow)
 \end{code}
index 6042f15..2cf2841 100644 (file)
@@ -256,6 +256,7 @@ data DynFlag
    | Opt_WarnDuplicateExports
    | Opt_WarnHiShadows
    | Opt_WarnIncompletePatterns
+   | Opt_WarnIncompletePatternsRecUpd
    | Opt_WarnMissingFields
    | Opt_WarnMissingMethods
    | Opt_WarnMissingSigs
index b3bda23..ac9e92c 100644 (file)
@@ -441,6 +441,7 @@ fFlags = [
   ( "warn-duplicate-exports",          Opt_WarnDuplicateExports ),
   ( "warn-hi-shadowing",               Opt_WarnHiShadows ),
   ( "warn-incomplete-patterns",        Opt_WarnIncompletePatterns ),
+  ( "warn-incomplete-record-updates",          Opt_WarnIncompletePatternsRecUpd ),
   ( "warn-missing-fields",             Opt_WarnMissingFields ),
   ( "warn-missing-methods",            Opt_WarnMissingMethods ),
   ( "warn-missing-signatures",         Opt_WarnMissingSigs ),
index fb215c7..ab61bd4 100644 (file)
          </row>
 
          <row>
+           <entry><option>-fwarn-incomplete-record-updates</option></entry>
+           <entry>warn when a record update could fail</entry>
+           <entry>dynamic</entry>
+           <entry><option>-fno-warn-incomplete-record-updates</option></entry>
+         </row>
+
+         <row>
            <entry><option>-fwarn-misc</option></entry>
            <entry>enable miscellaneous warnings</entry>
            <entry>dynamic</entry>
index 748e0b2..cc4f366 100644 (file)
@@ -835,6 +835,33 @@ g [] = 2
       </varlistentry>
 
       <varlistentry>
+       <term><option>-fwarn-incomplete-record-updates</option>:</term>
+       <listitem>
+         <indexterm><primary><option>-fwarn-incomplete-record-updates</option></primary></indexterm>
+         <indexterm><primary>incomplete record updates, warning</primary></indexterm>
+         <indexterm><primary>record updates, incomplete</primary></indexterm>
+
+         <para>The function
+          <function>f</function> below will fail when applied to
+          <literal>Bar</literal>, so the compiler will emit a warning about
+          this when <option>-fwarn-incomplete-record-updates</option> is
+          enabled.</para>
+
+<programlisting>
+data Foo = Foo { x :: Int }
+         | Bar
+
+f :: Foo -> Foo
+f foo = foo { x = 6 }
+</programlisting>
+
+         <para>This option isn't enabled be default because it can be
+          very noisy, and it often doesn't indicate a bug in the
+          program.</para>
+       </listitem>
+      </varlistentry>
+
+      <varlistentry>
        <term>
           <option>-fwarn-misc</option>:
           <indexterm><primary><option>-fwarn-misc</option></primary></indexterm>