Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ghc 40798 #454

Merged
merged 8 commits into from
Jun 14, 2022
7 changes: 7 additions & 0 deletions message-index/messages/GHC-40798/example1/after/Main.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{-# OPTIONS -Woperator-whitespace #-}

module Main where

main = print "notice the usage of whitespace below"
Reasonable-Solutions marked this conversation as resolved.
Show resolved Hide resolved

f a b = a + b
Reasonable-Solutions marked this conversation as resolved.
Show resolved Hide resolved
11 changes: 11 additions & 0 deletions message-index/messages/GHC-40798/example1/before/Main.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{-# OPTIONS -Woperator-whitespace #-}

module Main where

main = print "notice the usage of whitespace below"
Reasonable-Solutions marked this conversation as resolved.
Show resolved Hide resolved

f a b = a+ b -- this one is a warning

g a b = a +b -- this one is also a warning

h a b = a+b -- this one as well
Reasonable-Solutions marked this conversation as resolved.
Show resolved Hide resolved
35 changes: 35 additions & 0 deletions message-index/messages/GHC-40798/example1/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
---
title: operator-whitespace
summary: An optional warning for detecting usage of infix, suffix or prefix operators that could be parsed differently in the future due to whitespace, this warning is disabled by default.
Reasonable-Solutions marked this conversation as resolved.
Show resolved Hide resolved
severity: warning
flag: -Wall, -Wcompat, or -Woperator-whitespace
introduced: 9.6.1
---

## Error Message
```
Main.hs:7:10: warning: [-Woperator-whitespace] [GHC-40798]
The suffix use of a ‘+’ might be repurposed as special syntax
by a future language extension.
Suggested fix: Add whitespace around ‘+’.
|
7 | f a b = a+ b
| ^

Main.hs:9:11: warning: [-Woperator-whitespace] [GHC-40798]
The prefix use of a ‘+’ might be repurposed as special syntax
by a future language extension.
Suggested fix: Add whitespace around ‘+’.
|
9 | g a b = a +b
| ^

Main.hs:11:10: warning: [-Woperator-whitespace] [GHC-40798]
The tight infix use of a ‘+’ might be repurposed as special syntax
by a future language extension.
Suggested fix: Add whitespace around ‘+’.
|
11 | h a b = a+b
| ^

```
34 changes: 34 additions & 0 deletions message-index/messages/GHC-40798/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
---
title: Operator whitespace
summary: An optional warning for detecting usage of infix, suffix or prefix operators that could be parsed differently in future due to whitespace.
severity: warning
introduced: 9.6.1
---

GHC distinguishes between a few different occurences for operators depending on whitespace.
An operator can occur in the following ways:

```
a ! b -- a loose infix occurrence
a!b -- a tight infix occurrence
a !b -- a prefix occurrence
a! b -- a suffix occurrence
```
A loose infix occurrence will always be treated as an operator wheres any of the remaining cases can be redefined by some future language extension.
Reasonable-Solutions marked this conversation as resolved.
Show resolved Hide resolved

Consider `-XBangPatterns`

```
a ! b = <rhs> -- Infix (!)
f !a = <rhs> -- Bang pattern
```

the above code is possible today, whereas

```
a +b = <rhs>
```

would break if a language extension that introduces a prefix occurence for plus is introduced.

The documentation for the `-Woperator-whitespace` flag can be found in the [GHC user guide](https://downloads.haskell.org/ghc/latest/docs/html/users_guide/using-warnings.html?highlight=whitespace#ghc-flag--Woperator-whitespace)