-
Notifications
You must be signed in to change notification settings - Fork 55
Open
Description
GF doesn't make any syntactic distinction between how parameters, functions and variables are written. There is a convention that parameters should be capitalised, but functions and variables be lower-cased, but it's not enforced. This leads to problems, here is an example:
abstract TestAbs = {
cat S; B;
fun sOk, sBug : B -> B -> S;
fun bTrue, bFalse : B;
}
concrete Test of TestAbs = {
param Bool = True | False;
lincat S = {s : Str};
lincat B = {s : Str; b : Bool};
lin sOk x y = {s = x.s ++ y.s ++ case <x.b, y.b> of {
<True, False> => "<TrueFalse>" ;
<_, _ > => ""
}};
lin sBug x y = {s = x.s ++ y.s ++ case <x.b, y.b> of {
<True, Fasle> => "<TrueFasle>" ;
<_, _ > => ""
}};
lin bTrue = {s = "True"; b = True};
lin bFalse = {s = "False"; b = False};
}
The only difference is that False is misspelled in sBug. Here's the result:
> i -src Test.gf
- compiling TestAbs.gf... write file TestAbs.gfo
- compiling Test.gf... write file Test.gfo
linking ... OK
TestAbs> gt sOk ? ? | l
False False
False True
True False <TrueFalse>
True True
TestAbs> gt sBug ? ? | l
False False
False True
True False <TrueFasle>
True True <TrueFasle>
The misspelling of Fasle makes it a parameter variable which then captures <True,True> too, which was not intended. This bug is very difficult to catch, because GF didn't print any warning at all.
How can we capture these errors better?
Metadata
Metadata
Assignees
Labels
No labels