lang: Catch duplicate resource fields or meta entries statically

This teaches the compiler to catch entries with duplicate fields, and
duplicate meta entries, because it could be ambiguous to determine which
should take precedence. For example, if you specified `content` to a
file resource twice, this should error. This is known statically, so we
can catch it. If you specified two `Meta:noop` entries, this can also be
caught.

The interesting part happens when you specify one `Meta:noop` entry, and
one `Meta` entry which happens to contain a noop field in the struct.
For this, we actually have to wait until type unification is finished,
and catch the error there. This is because after type unification we
will know the precise type of the struct being passed to `Meta`, and so
we can look at its field names, even if their values aren't yet known
because the graph hasn't run yet.
This commit is contained in:
James Shubin
2021-05-07 22:59:11 -04:00
parent 0756133a7e
commit 37be9fda9f
18 changed files with 153 additions and 73 deletions

View File

@@ -222,7 +222,6 @@ func TestInterpret4(t *testing.T) {
int64 => 42,
boolptr => true,
# comment 3
stringptr => "the actual field name is: StringPtr", # comment 4
int8ptr => 99, # comment 5
comment => "☺\thello\nwo\"rld\\2", # must escape these
}
@@ -240,8 +239,6 @@ func TestInterpret4(t *testing.T) {
x.Int64 = 42
b := true
x.BoolPtr = &b
stringptr := "the actual field name is: StringPtr"
x.StringPtr = &stringptr
int8ptr := int8(99)
x.Int8Ptr = &int8ptr
x.Comment = "☺\thello\nwo\"rld\\2" // must escape the escaped chars