Open On3d4y opened 5 years ago
I'd say this is more of a feature request than a bug report @Southclaws. Since apparently pawn-lang.pdf says this shouldn't be allowed, the fact that it isn't is correct. Actually, as a feature request it might be nice to go one further:
Func() <my_state: state_a> // Function in state `state_a` of automata `my_state`.
{
}
Func() <> // Fallback function.
{
}
That code is fine - you have a fallback function, and the automata for the function (since it can only have one) is well defined by another instance.
Func() <my_state: state_a> // Function in state `state_a` of automata `my_state`.
{
}
Func() <my_state> // Function in state `my_state` of the default automata.
{
}
That code is an error, since the compiler thinks you are putting Func
in two different automata. The syntax proposed in the original post is also an error:
Func() <my_state: state_a> // Function in state `state_a` of automata `my_state`.
{
}
Func() <my_state:> // Fallback function explicitly in automata `my_state`.
{
}
Normally this is not an issue, since you tend to have multiple copies of a function when using states. A stateful function with only one state is pointless - that's just a normal function. But it does happen, especially with libraries and hooks. I do this with one version of ALS:
OnWhatever() <_ALS: dummy> { return 1; }
OnWhatever() <> { return 1; }
Then if there is a hook, the hook is called in state _ALS: exists
; if there is no hook the fallback is called. The dummy function exists purely to set the automata. You can specify multiple states:
OnWhatever() <_ALS: dummy, _ALS: other> { return 1; }
But there's no way to specify multiple states including the fallback explicitly:
OnWhatever() <_ALS: dummy, > { return 1; }
Which wouldn't be needed either if there was a way to specify the automata explicitly as above:
OnWhatever() <_ALS: > { return 1; }
Furthermore, if ONLY a fallback function exists (explicit or otherwise) the whole state stub can be simply omitted and the function treat as a normal function. In that case, the explicit automata specification becomes unnecessary and the error should be removed:
OnWhatever() <> { return 1; }
That would be called in all cases (thus not needing the internal switch
), and if a hook did exist as:
OnWhatever() <_ALS: exists>
{
// Code.
}
The compiler would put all versions in the same automata and thus generate the switch.
But back to the point about variables. They WOULD need the explicit automata specification for fallback, since they can have different names. So I'd say allow that <automata:>
syntax for functions as well even if it isn't needed.
It also turns out that two variables in mutually exclusive states can't have the same name. Since the documentation talks about them being a temporal scope that should be allowed.
This issue has been automatically marked as stale because it has not had recent activity.
Issue description:
In pawn-lang.pdf:
Minimal complete verifiable example (MCVE):
Why not one
var3
can work?Workspace Information: