From fe2725d9eecb8db27729b36a5d6f715478c3acc7 Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Sun, 14 Feb 2016 16:16:11 -0800 Subject: 2653 --- 033exclusive_container.cc | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/033exclusive_container.cc b/033exclusive_container.cc index e6da34f0..ea2d8e3a 100644 --- a/033exclusive_container.cc +++ b/033exclusive_container.cc @@ -99,15 +99,13 @@ case MAYBE_CONVERT: { if (inst.products.empty()) break; reagent product = inst.products.at(0); if (!canonize_type(product)) break; - const reagent& offset = inst.ingredients.at(1); - long long int tag = 0; - if (is_integer(offset.name)) { - tag = to_integer(offset.name); - } - else { - tag = offset.value; + reagent& offset = inst.ingredients.at(1); + populate_value(offset); + if (offset.value >= SIZE(get(Type, base.type->value).elements)) { + raise_error << maybe(caller.name) << "invalid tag " << offset.value << " in '" << inst.to_string() << '\n' << end(); + break; } - reagent variant = variant_type(base, tag); + reagent variant = variant_type(base, offset.value); variant.type = new type_tree(get(Type_ordinal, "address"), variant.type); if (!types_coercible(product, variant)) { raise_error << maybe(caller.name) << "'maybe-convert " << base.original_string << ", " << inst.ingredients.at(1).original_string << "' should write to " << debug_string(variant.type) << " but " << product.name << " has type " << debug_string(product.type) << '\n' << end(); @@ -188,8 +186,8 @@ exclusive-container foo [ recipe main [ 1:number <- copy 34 - 2:foo <- merge 0/x, 1:number - 4:foo <- merge 1/x, 1:number + 2:foo <- merge 0/x, 1:number # tag must be a literal when merging exclusive containers + 4:foo <- merge 1/y, 1:number ] +mem: storing 0 in location 2 +mem: storing 34 in location 3 -- cgit 1.4.1-2-gfad0 rser.h'>stats
path: root/tests/unittests/test_parser.h
blob: 51d768fec610d38f17c8d9e17444d1193c88c0ea (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50