问题
Alloy appears to have a bug when relations include unconstrained Strings. No instance is found for the following:
sig foo{
bar: String,
yak: Int
}
pred show[]{one f:foo | f.yak=0}
run show for 1
If we change this to bar: Int
, Alloy finds an instance with an arbitrary value.
回答1:
This "known for ages" bug has thankfully a workaround. For things to work, you need to "implicitly declare" some string values by using them in a fact or a predicate.
As an example, the following signature fact will allow bar to take its value in {"a","b","c"} :
sig foo{
bar: String,
yak: Int
}{
bar in "a"+"b"+"c"
}
You can also define a pool of string to be used instance wide as follows:
fact stringPool{
none!= "a"+"b"+"c"+"d"+"e"
}
See:
Provide Alloy with a "pool" of custom Strings
Problem in generation of world in predicate
How to use String in Alloy?
and so on ...
回答2:
Thanks for the bug report. Can you file an issue?
BTW, strings are not well supported in Alloy. In general it's best to avoid any concrete types unless you really need them, and do everything with abstract ones. Most uses of integers aren't necessary either.
来源:https://stackoverflow.com/questions/57503426/bug-on-unconstrained-strings