summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPéter Diviánszky <divipp@gmail.com>2016-01-22 22:04:18 +0100
committerPéter Diviánszky <divipp@gmail.com>2016-01-22 22:09:03 +0100
commit838f88bcf9572eb77b4a00e847f8d06fcc227a20 (patch)
tree4bec45fe981e70e68ee1b954e80f47f54d0e3d37
parentad899f80977e97a0d016852b4bc4d0be5a521ac2 (diff)
do not allow multiple alternatives for 0 arity functions
-rw-r--r--src/LambdaCube/Compiler/Infer.hs28
-rw-r--r--testdata/language-features/basic-values/redefine02.reject.lc (renamed from testdata/language-features/basic-values/redefine02.reject.wip.lc)0
-rw-r--r--testdata/language-features/basic-values/redefine02.reject.out3
-rw-r--r--testdata/language-features/basic-values/redefine03.reject.lc (renamed from testdata/language-features/basic-values/redefine03.reject.wip.lc)0
-rw-r--r--testdata/language-features/basic-values/redefine03.reject.out4
5 files changed, 22 insertions, 13 deletions
diff --git a/src/LambdaCube/Compiler/Infer.hs b/src/LambdaCube/Compiler/Infer.hs
index c3b13b82..00106612 100644
--- a/src/LambdaCube/Compiler/Infer.hs
+++ b/src/LambdaCube/Compiler/Infer.hs
@@ -1853,19 +1853,21 @@ compileFunAlts par ulend lend ge ds = \case
1853 [] -> return tf -- builtin type family 1853 [] -> return tf -- builtin type family
1854 alts -> compileFunAlts True id SLabelEnd ge [TypeAnn n $ addParamsS ps t] alts 1854 alts -> compileFunAlts True id SLabelEnd ge [TypeAnn n $ addParamsS ps t] alts
1855 [p@PrecDef{}] -> return [p] 1855 [p@PrecDef{}] -> return [p]
1856 fs@((FunAlt n vs _): _) 1856 fs@((FunAlt n vs _): _) -> case map head $ group [length vs | FunAlt _ vs _ <- fs] of
1857 | ls@(_:_:_) <- map head $ group [length vs | FunAlt _ vs _ <- fs] -> fail $ "different number of arguments of " ++ snd n ++ " at " ++ showSIRange (fst n) 1857 [num]
1858 | any (== n) [n' | TypeFamily n' _ _ <- ds] -> return [] 1858 | num == 0 && length fs > 1 -> fail $ "redefined " ++ snd n ++ " at " ++ showSIRange (fst n)
1859 | otherwise -> return 1859 | any (== n) [n' | TypeFamily n' _ _ <- ds] -> return []
1860 [ Let n 1860 | otherwise -> return
1861 (listToMaybe [t | PrecDef n' t <- ds, n' == n]) 1861 [ Let n
1862 (listToMaybe [t | TypeAnn n' t <- ds, n' == n]) 1862 (listToMaybe [t | PrecDef n' t <- ds, n' == n])
1863 (map (fst . fst) vs) 1863 (listToMaybe [t | TypeAnn n' t <- ds, n' == n])
1864 (foldr (uncurry SLam) (compileGuardTrees par ulend lend ge 1864 (map (fst . fst) vs)
1865 [ compilePatts (zip (map snd vs) $ reverse [0..length vs - 1]) gsx 1865 (foldr (uncurry SLam) (compileGuardTrees par ulend lend ge
1866 | FunAlt _ vs gsx <- fs 1866 [ compilePatts (zip (map snd vs) $ reverse [0.. num - 1]) gsx
1867 ]) (map fst vs)) 1867 | FunAlt _ vs gsx <- fs
1868 ] 1868 ]) (map fst vs))
1869 ]
1870 _ -> fail $ "different number of arguments of " ++ snd n ++ " at " ++ showSIRange (fst n)
1869 x -> return x 1871 x -> return x
1870 where 1872 where
1871 noTA x = ((Visible, Wildcard SType), x) 1873 noTA x = ((Visible, Wildcard SType), x)
diff --git a/testdata/language-features/basic-values/redefine02.reject.wip.lc b/testdata/language-features/basic-values/redefine02.reject.lc
index 7510e602..7510e602 100644
--- a/testdata/language-features/basic-values/redefine02.reject.wip.lc
+++ b/testdata/language-features/basic-values/redefine02.reject.lc
diff --git a/testdata/language-features/basic-values/redefine02.reject.out b/testdata/language-features/basic-values/redefine02.reject.out
new file mode 100644
index 00000000..790b6e63
--- /dev/null
+++ b/testdata/language-features/basic-values/redefine02.reject.out
@@ -0,0 +1,3 @@
1"testdata/language-features/basic-values/redefine02.reject.lc" (line 3, column 9):
2expecting lowercase ident, uppercase ident or operator definition
3Invalid indentation. Found a token at indentation 8. Expecting a token at an indentation greater than or equal to 13.IndentStream {indentationState = IndentationState {minIndentation = 13, maxIndentation = 14, absMode = False, tokenRel = Ge}, tokenStream = ""} or Invalid indentation. Found a token at indentation 8. Expecting a token at an indentation greater than or equal to 12.IndentStream {indentationState = IndentationState {minIndentation = 12, maxIndentation = 12, absMode = False, tokenRel = Ge}, tokenStream = ""} \ No newline at end of file
diff --git a/testdata/language-features/basic-values/redefine03.reject.wip.lc b/testdata/language-features/basic-values/redefine03.reject.lc
index 62e5705e..62e5705e 100644
--- a/testdata/language-features/basic-values/redefine03.reject.wip.lc
+++ b/testdata/language-features/basic-values/redefine03.reject.lc
diff --git a/testdata/language-features/basic-values/redefine03.reject.out b/testdata/language-features/basic-values/redefine03.reject.out
new file mode 100644
index 00000000..05f009e1
--- /dev/null
+++ b/testdata/language-features/basic-values/redefine03.reject.out
@@ -0,0 +1,4 @@
1"testdata/language-features/basic-values/redefine03.reject.lc" (line 4, column 1):
2unexpected end of input
3expecting ".", "%", character, literal string, float, "#", natural, "_", "'", lowercase ident, "(", uppercase ident, "[", List comprehension, "{", "let", "@", symbols, ":", backquoted, "::", "~", "->", "=>", "where", "data", "class", "instance", "type", "infix", "infixl", "infixr" or operator definition
4redefined x at testdata/language-features/basic-values/redefine03.reject.lc 2:9-2:10 \ No newline at end of file