Suppose I had the following Emboss definition. Such a definition creates a requirement bound on the value of bar while also exposing max_value virtual field programmatically via Foo::max_value(). It allows developers to keep the minimum or maximum bounds defined in one place and referred to elsewhere, including their code.
struct Foo:
let max_value = 128
0 [+1] UInt bar
[requires: 0 <= this <= max_value]
However, this is currently not possible. According to the language reference, "for [requires] on a field, other fields may not be referenced."
There is a workaround:
struct Foo:
[requires: 0 <= bar <= max_value]
let max_value = 128
0 [+1] UInt bar
While this accomplishes the same goal, I would say it's not as good as being able to refer to other fields from a [requires] on a field itself. If I had multiple of these requirement blocks, it could get pretty unwieldy to have them all at the top instead of closer to where they semantically matter.
Suppose I had the following Emboss definition. Such a definition creates a requirement bound on the value of
bar
while also exposingmax_value
virtual field programmatically viaFoo::max_value()
. It allows developers to keep the minimum or maximum bounds defined in one place and referred to elsewhere, including their code.However, this is currently not possible. According to the language reference, "for
[requires]
on a field, other fields may not be referenced."There is a workaround:
While this accomplishes the same goal, I would say it's not as good as being able to refer to other fields from a
[requires]
on a field itself. If I had multiple of these requirement blocks, it could get pretty unwieldy to have them all at the top instead of closer to where they semantically matter.