diff options
author | Ömer Sinan Ağacan <omeragacan@gmail.com> | 2016-09-26 17:09:01 -0400 |
---|---|---|
committer | Ömer Sinan Ağacan <omeragacan@gmail.com> | 2016-09-26 17:09:13 -0400 |
commit | c36904d66f30d4386a231ce365a056962a881767 (patch) | |
tree | fd57bc9336b07db13678d05f16ce3ea50bb648b4 /testsuite/tests/parser | |
parent | b0ae0ddf4e5807e4d66e5da0f7acf68edd76e289 (diff) | |
download | haskell-c36904d66f30d4386a231ce365a056962a881767.tar.gz |
Fix layout of MultiWayIf expressions (#10807)
With this patch we stop generating virtual semicolons in MultiWayIf
guards. Fixes #10807.
Test Plan:
Reviewers: simonmar, austin, bgamari
Reviewed By: simonmar
Subscribers: mpickering, thomie
Differential Revision: https://phabricator.haskell.org/D2524
GHC Trac Issues: #10807
Diffstat (limited to 'testsuite/tests/parser')
-rw-r--r-- | testsuite/tests/parser/should_run/T10807.hs | 43 | ||||
-rw-r--r-- | testsuite/tests/parser/should_run/T10807.stdout | 4 | ||||
-rw-r--r-- | testsuite/tests/parser/should_run/all.T | 1 |
3 files changed, 48 insertions, 0 deletions
diff --git a/testsuite/tests/parser/should_run/T10807.hs b/testsuite/tests/parser/should_run/T10807.hs new file mode 100644 index 0000000000..8f6546201e --- /dev/null +++ b/testsuite/tests/parser/should_run/T10807.hs @@ -0,0 +1,43 @@ +{-# LANGUAGE MultiWayIf #-} + +module Main where + +-- This is how we had to use multi-way if previously. Not indenting lines after +-- `|` was causing a parse error. +f1 x = if | even x + , x /= 0 + -> True + | otherwise + -> False + +-- This was previously causing a parse error, but actually it should work. +f2 x = if | even x + , x /= 0 + -> True + | otherwise + -> False + +-- If we don't generate {} in MultiWayIf we get a shift/reduce conflict here: +-- It's not clear which guards belong to `case` and which ones belong to `if`. +-- +-- This test is to make sure we parse it correctly. +-- +-- - If we shift, we get a non-exhaustive pattern error when argument is odd. +-- - If we reduce, we run the unreachable code when argument is odd. +f3 x = case x of + x' | even x' -> if | even x' -> 1 | otherwise -> error "should be unreachable" + | otherwise -> 3 + +-- Testing line breaks +f4 x = case x of + x' | even x' -> if + | even x' -> 1 + | otherwise -> error "should be unreachable" + | otherwise -> 3 + +main :: IO () +main = do + print (f3 1) + print (f3 2) + print (f4 1) + print (f4 2) diff --git a/testsuite/tests/parser/should_run/T10807.stdout b/testsuite/tests/parser/should_run/T10807.stdout new file mode 100644 index 0000000000..9fcb40e7af --- /dev/null +++ b/testsuite/tests/parser/should_run/T10807.stdout @@ -0,0 +1,4 @@ +3 +1 +3 +1 diff --git a/testsuite/tests/parser/should_run/all.T b/testsuite/tests/parser/should_run/all.T index 8a72c421ab..bb5e4fde39 100644 --- a/testsuite/tests/parser/should_run/all.T +++ b/testsuite/tests/parser/should_run/all.T @@ -9,3 +9,4 @@ test('ParserMultiWayIf', [], compile_and_run, ['']) test('BinaryLiterals0', normal, compile_and_run, ['']) test('BinaryLiterals1', [], compile_and_run, ['']) test('BinaryLiterals2', [], compile_and_run, ['']) +test('T10807', normal, compile_and_run, ['']) |