diff options
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, ['']) |