Mention which -Werror promoted a warning to an error
authorÖmer Sinan Ağacan <omeragacan@gmail.com>
Tue, 11 Jul 2017 19:41:20 +0000 (15:41 -0400)
committerBen Gamari <ben@smart-cactus.org>
Tue, 11 Jul 2017 20:32:43 +0000 (16:32 -0400)
commit4befb415d7ee63d2b0ecdc2384310dc4b3ccc90a
treef0baf272b60c130ca4fe4eaf9e7c39c3fa123abb
parent3a163aabe7948d382393e9e81f1239f3e06b222b
Mention which -Werror promoted a warning to an error

Previously -Werror or -Werror=flag printed warnings as usual and then
printed
these two lines:

    <no location info>: error:
    Failing due to -Werror.

This is not ideal: first, it's not clear which flag made one of the
warnings an
error. Second, warning messages are not modified in any way, so there's
no way
to know which warnings caused this error.

With this patch we (1) promote warning messages to error messages if a
relevant
-Werror is enabled (2) mention which -Werror is used during this
promotion.

Previously:

    [1 of 1] Compiling Main             ( test.hs, test.o )

    test.hs:9:10: warning: [-Wincomplete-patterns]
        Pattern match(es) are non-exhaustive
        In a case alternative: Patterns not matched: (C2 _)
      |
    9 | sInt s = case s of
      |          ^^^^^^^^^...

    test.hs:12:14: warning: [-Wmissing-fields]
        • Fields of ‘Rec’ not initialised: f2
        • In the first argument of ‘print’, namely ‘Rec {f1 =
1}’
          In the expression: print Rec {f1 = 1}
          In an equation for ‘main’: main = print Rec {f1 = 1}
       |
    12 | main = print Rec{ f1 = 1 }
       |              ^^^^^^^^^^^^^

    <no location info>: error:
    Failing due to -Werror.

Now:

    [1 of 1] Compiling Main             ( test.hs, test.o )

    test.hs:9:10: error: [-Wincomplete-patterns,
-Werror=incomplete-patterns]
        Pattern match(es) are non-exhaustive
        In a case alternative: Patterns not matched: (C2 _)
      |
    9 | sInt s = case s of
      |          ^^^^^^^^^...

    test.hs:12:14: error: [-Wmissing-fields, -Werror=missing-fields]
        • Fields of ‘Rec’ not initialised: f2
        • In the first argument of ‘print’, namely ‘Rec {f1 =
1}’
          In the expression: print Rec {f1 = 1}
          In an equation for ‘main’: main = print Rec {f1 = 1}
       |
    12 | main = print Rec{ f1 = 1 }
       |              ^^^^^^^^^^^^^

Test Plan: - Update old tests, add new tests if there aren't any
relevant tests

Reviewers: austin, bgamari

Reviewed By: bgamari

Subscribers: rwbarton, thomie

Differential Revision: https://phabricator.haskell.org/D3709
28 files changed:
compiler/main/DynFlags.hs
compiler/main/ErrUtils.hs
compiler/main/HscTypes.hs
compiler/rename/RnNames.hs
compiler/typecheck/Inst.hs
compiler/typecheck/TcRnExports.hs
compiler/typecheck/TcRnMonad.hs
compiler/typecheck/TcSigs.hs
testsuite/tests/driver/T11429c.stderr
testsuite/tests/driver/werror.stderr
testsuite/tests/overloadedrecflds/should_fail/overloadedrecfldsfail05.stderr
testsuite/tests/overloadedrecflds/should_fail/overloadedrecfldsfail06.stderr
testsuite/tests/overloadedrecflds/should_fail/overloadedrecfldsfail11.stderr
testsuite/tests/overloadedrecflds/should_fail/overloadedrecfldsfail12.stderr
testsuite/tests/patsyn/should_fail/UnliftedPSBind.stderr
testsuite/tests/patsyn/should_fail/unboxed-bind.stderr
testsuite/tests/rename/should_fail/T5892a.stderr
testsuite/tests/safeHaskell/flags/SafeFlags18.stderr
testsuite/tests/safeHaskell/flags/SafeFlags23.stderr
testsuite/tests/safeHaskell/flags/SafeFlags26.stderr
testsuite/tests/safeHaskell/overlapping/SH_Overlap7.stderr
testsuite/tests/safeHaskell/safeInfered/UnsafeInfered12.stderr
testsuite/tests/typecheck/should_fail/T3966.stderr
testsuite/tests/typecheck/should_fail/tcfail204.stderr
testsuite/tests/warnings/should_fail/WerrorFail.stderr
testsuite/tests/warnings/should_fail/WerrorFail2.hs [new file with mode: 0644]
testsuite/tests/warnings/should_fail/WerrorFail2.stderr [new file with mode: 0644]
testsuite/tests/warnings/should_fail/all.T