From a4e3bce6bba915ea9dba0c1a34519f9cde9d243e Mon Sep 17 00:00:00 2001 From: Inari Listenmaa Date: Thu, 4 Jun 2020 19:56:31 +0200 Subject: Add clarification to "Pattern is not linear" error msg. --- src/compiler/GF/Compile/Compute/ConcreteNew.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/compiler/GF/Compile/Compute') diff --git a/src/compiler/GF/Compile/Compute/ConcreteNew.hs b/src/compiler/GF/Compile/Compute/ConcreteNew.hs index a9ae63960..0edf43c8d 100644 --- a/src/compiler/GF/Compile/Compute/ConcreteNew.hs +++ b/src/compiler/GF/Compile/Compute/ConcreteNew.hs @@ -546,7 +546,7 @@ value2term' stop loc xs v0 = linPattVars p = if null dups then return pvs - else fail.render $ hang "Pattern is not linear:" 4 (ppPatt Unqualified 0 p) + else fail.render $ hang "Pattern is not linear. All variable names on the left-hand side must be distinct." 4 (ppPatt Unqualified 0 p) where allpvs = allPattVars p pvs = nub allpvs -- cgit v1.2.3 From dca1fcd7febf59728819736a08eb572d5d10b3c6 Mon Sep 17 00:00:00 2001 From: Inari Listenmaa Date: Thu, 4 Jun 2020 19:57:38 +0200 Subject: Add clarification to Unsupported token gluing (both good and bad case) --- src/compiler/GF/Compile/Compute/ConcreteNew.hs | 33 +++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) (limited to 'src/compiler/GF/Compile/Compute') diff --git a/src/compiler/GF/Compile/Compute/ConcreteNew.hs b/src/compiler/GF/Compile/Compute/ConcreteNew.hs index 0edf43c8d..9a8024697 100644 --- a/src/compiler/GF/Compile/Compute/ConcreteNew.hs +++ b/src/compiler/GF/Compile/Compute/ConcreteNew.hs @@ -291,9 +291,36 @@ glue env (v1,v2) = glu v1 v2 vt v = case value2term loc (local env) v of Left i -> Error ('#':show i) Right t -> t - in error . render $ - ppL loc (hang "unsupported token gluing:" 4 - (Glue (vt v1) (vt v2))) + originalMsg = render $ ppL loc (hang "unsupported token gluing" 4 + (Glue (vt v1) (vt v2))) + term = render $ pp $ Glue (vt v1) (vt v2) + in error $ unlines + [originalMsg + ,"" + ,"There was a problem in the expression `" ++ term ++ "`" + ,"This can be due to two causes, check which one applies in your case." + ,"" + ,"1) You are trying to use + on runtime arguments. Even if you are using" + ," `"++term++"` in an oper, make sure that the oper isn't called in a" + ," linearization that takes arguments. Both of the following are illegal:" + ,"" + ," lin Test foo bar = foo.s + bar.s <- explicit + in a lin" + ," lin Test foo bar = opWithPlus foo bar <- the oper uses +" + ,"" + ,"2) One of the arguments in `"++term++"` is a bound variable" + ," from pattern matching a string, but the cases are non-exhaustive." + ," Example:" + ," case \"test\" of {" + ," x + \"a\" => x + \"b\" <- no applicable case for \"test\", so x = ???" + ," } ;" + ,"" + ," You can fix this by adding a catch-all case in the end:" + ," { x + \"a\" => x + \"b\" ;" + ," _ => \"default case\" } ;" + ,"" + ,"3) If neither applies, submit a bug report and we update the error message." + ," https://github.com/GrammaticalFramework/gf-core/issues" + ] -- | to get a string from a value that represents a sequence of terminals -- cgit v1.2.3 From de8cc02ba58d11957defdc89b6755eeb0b548fde Mon Sep 17 00:00:00 2001 From: Inari Listenmaa Date: Fri, 5 Jun 2020 19:39:31 +0200 Subject: Condense the unsupported token gluing as per John's suggestion --- doc/errors/gluing.md | 27 ++++++++++++++++++++++++++ src/compiler/GF/Compile/Compute/ConcreteNew.hs | 27 ++++---------------------- 2 files changed, 31 insertions(+), 23 deletions(-) create mode 100644 doc/errors/gluing.md (limited to 'src/compiler/GF/Compile/Compute') diff --git a/doc/errors/gluing.md b/doc/errors/gluing.md new file mode 100644 index 000000000..111f8406c --- /dev/null +++ b/doc/errors/gluing.md @@ -0,0 +1,27 @@ +## unsupported token gluing `foo + bar` + +There was a problem in an expression using +, e.g. `foo + bar`. +This can be due to two causes, check which one applies in your case. + +1. You are trying to use + on runtime arguments. Even if you are using +`foo + bar` in an oper, make sure that the oper isn't called in a +linearization that takes arguments. Both of the following are illegal: + + lin Test foo bar = foo.s + bar.s -- explicit + in a lin + lin Test foo bar = opWithPlus foo bar -- the oper uses + + +2. One of the arguments in `foo + bar` is a bound variable +from pattern matching a string, but the cases are non-exhaustive. +Example: + case "test" of { + x + "a" => x + "b" -- no applicable case for "test", so x = ??? + } ; + +You can fix this by adding a catch-all case in the end: + { x + "a" => x + "b" ; + _ => "default case" } ; + +3. If neither applies to your problem, submit a bug report and we +will update the error message and this documentation. + + https://github.com/GrammaticalFramework/gf-core/issues diff --git a/src/compiler/GF/Compile/Compute/ConcreteNew.hs b/src/compiler/GF/Compile/Compute/ConcreteNew.hs index 9a8024697..ea55e77cb 100644 --- a/src/compiler/GF/Compile/Compute/ConcreteNew.hs +++ b/src/compiler/GF/Compile/Compute/ConcreteNew.hs @@ -297,29 +297,10 @@ glue env (v1,v2) = glu v1 v2 in error $ unlines [originalMsg ,"" - ,"There was a problem in the expression `" ++ term ++ "`" - ,"This can be due to two causes, check which one applies in your case." - ,"" - ,"1) You are trying to use + on runtime arguments. Even if you are using" - ," `"++term++"` in an oper, make sure that the oper isn't called in a" - ," linearization that takes arguments. Both of the following are illegal:" - ,"" - ," lin Test foo bar = foo.s + bar.s <- explicit + in a lin" - ," lin Test foo bar = opWithPlus foo bar <- the oper uses +" - ,"" - ,"2) One of the arguments in `"++term++"` is a bound variable" - ," from pattern matching a string, but the cases are non-exhaustive." - ," Example:" - ," case \"test\" of {" - ," x + \"a\" => x + \"b\" <- no applicable case for \"test\", so x = ???" - ," } ;" - ,"" - ," You can fix this by adding a catch-all case in the end:" - ," { x + \"a\" => x + \"b\" ;" - ," _ => \"default case\" } ;" - ,"" - ,"3) If neither applies, submit a bug report and we update the error message." - ," https://github.com/GrammaticalFramework/gf-core/issues" + ,"There was a problem in the expression `"++term++"`, either:" + ,"1) You are trying to use + on runtime arguments, possibly via an oper." + ,"2) One of the arguments in `"++term++"` is a bound variable from pattern matching a string, but the cases are non-exhaustive." + ,"For more help see https://github.com/GrammaticalFramework/gf-core/tree/master/doc/errors/gluing.md" ] -- cgit v1.2.3