"Fossies" - the Fresh Open Source Software Archive

Member "ponyc-0.33.2/test/libponyc/refer.cc" (3 Feb 2020, 17779 Bytes) of package /linux/misc/ponyc-0.33.2.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. See also the latest Fossies "Diffs" side-by-side code changes report for "refer.cc": 0.33.1_vs_0.33.2.

    1 #include <gtest/gtest.h>
    2 #include <platform.h>
    3 
    4 #include "util.h"
    5 
    6 
    7 #define TEST_COMPILE(src) DO(test_compile(src, "refer"))
    8 
    9 #define TEST_ERRORS_1(src, err1) \
   10   { const char* errs[] = {err1, NULL}; \
   11     DO(test_expected_errors(src, "refer", errs)); }
   12 
   13 #define TEST_ERRORS_2(src, err1, err2) \
   14   { const char* errs[] = {err1, err2, NULL}; \
   15     DO(test_expected_errors(src, "refer", errs)); }
   16 
   17 #define TEST_ERRORS_3(src, err1, err2, err3) \
   18   { const char* errs[] = {err1, err2, err3, NULL}; \
   19     DO(test_expected_errors(src, "refer", errs)); }
   20 
   21 
   22 class ReferTest : public PassTest
   23 {};
   24 
   25 
   26 TEST_F(ReferTest, ConsumeThis)
   27 {
   28   const char* src =
   29     "class iso C\n"
   30       "fun iso get(): C iso^ =>\n"
   31         "consume this\n"
   32 
   33     "primitive P\n"
   34       "fun apply(c: C) => None\n"
   35 
   36     "actor Main\n"
   37       "new create(env: Env) =>\n"
   38         "let c = C\n"
   39         "(consume c).get()";
   40 
   41   TEST_COMPILE(src);
   42 }
   43 
   44 TEST_F(ReferTest, ConsumeThisReuse)
   45 {
   46   const char* src =
   47     "class iso C\n"
   48       "fun iso get(): C iso^ =>\n"
   49         "consume this\n"
   50         "consume this\n"
   51 
   52     "primitive P\n"
   53       "fun apply(c: C) => None\n"
   54 
   55     "actor Main\n"
   56       "new create(env: Env) =>\n"
   57         "let c = C\n"
   58         "(consume c).get()";
   59 
   60   TEST_ERRORS_1(src,
   61     "can't use a consumed 'this' in an expression");
   62 }
   63 
   64 TEST_F(ReferTest, ConsumeLet)
   65 {
   66   const char* src =
   67     "class iso C\n"
   68 
   69     "primitive P\n"
   70       "fun apply(c: C) => None\n"
   71 
   72     "actor Main\n"
   73       "new create(env: Env) =>\n"
   74         "let c = C\n"
   75         "P(consume c)";
   76 
   77   TEST_COMPILE(src);
   78 }
   79 
   80 TEST_F(ReferTest, ConsumeLetReassign)
   81 {
   82   const char* src =
   83     "class iso C\n"
   84 
   85     "actor Main\n"
   86       "new create(env: Env) =>\n"
   87         "let c = C\n"
   88         "c = consume c";
   89 
   90   TEST_ERRORS_2(src,
   91     "can't reassign to a let local",
   92     "left side must be something that can be assigned to");
   93 }
   94 
   95 TEST_F(ReferTest, ConsumeLetField)
   96 {
   97   const char* src =
   98     "class iso C\n"
   99 
  100     "primitive P\n"
  101       "fun apply(c: C) => None\n"
  102 
  103     "actor Main\n"
  104       "let c: C\n"
  105       "new create(env: Env) =>\n"
  106         "c = C\n"
  107         "P(consume c)";
  108 
  109   TEST_ERRORS_1(src,
  110     "can't consume a let or embed field");
  111 }
  112 
  113 TEST_F(ReferTest, ConsumeVar)
  114 {
  115   const char* src =
  116     "class iso C\n"
  117 
  118     "primitive P\n"
  119       "fun apply(c: C) => None\n"
  120 
  121     "actor Main\n"
  122       "new create(env: Env) =>\n"
  123         "var c = C\n"
  124         "P(consume c)";
  125 
  126   TEST_COMPILE(src);
  127 }
  128 
  129 TEST_F(ReferTest, ConsumeVarReuse)
  130 {
  131   const char* src =
  132     "class iso C\n"
  133 
  134     "primitive P\n"
  135       "fun apply(c: C) => None\n"
  136 
  137     "actor Main\n"
  138       "new create(env: Env) =>\n"
  139         "var c = C\n"
  140         "consume c\n"
  141         "P(consume c)";
  142 
  143   TEST_ERRORS_2(src,
  144     "can't use a consumed local or field in an expression",
  145     "consume must take 'this', a local, or a parameter");
  146 }
  147 
  148 TEST_F(ReferTest, ConsumeVarReassign)
  149 {
  150   const char* src =
  151     "class iso C\n"
  152 
  153     "actor Main\n"
  154       "new create(env: Env) =>\n"
  155         "var c = C\n"
  156         "c = consume c";
  157 
  158   TEST_COMPILE(src);
  159 }
  160 
  161 TEST_F(ReferTest, ConsumeVarField)
  162 {
  163   const char* src =
  164     "class iso C\n"
  165 
  166     "primitive P\n"
  167       "fun apply(c: C) => None\n"
  168 
  169     "actor Main\n"
  170       "var c: C\n"
  171       "new create(env: Env) =>\n"
  172         "c = C\n"
  173         "P(consume c)";
  174 
  175   TEST_ERRORS_1(src,
  176     "consuming a field is only allowed if it is reassigned in the same"
  177     " expression");
  178 }
  179 
  180 TEST_F(ReferTest, ConsumeVarFieldReassign)
  181 {
  182   const char* src =
  183     "class iso C\n"
  184 
  185     "primitive P\n"
  186       "fun apply(c: C): C iso^ => consume c\n"
  187 
  188     "actor Main\n"
  189       "var c: C\n"
  190       "new create(env: Env) =>\n"
  191         "c = C\n"
  192         "c = P(consume c)";
  193 
  194   TEST_COMPILE(src);
  195 }
  196 
  197 TEST_F(ReferTest, ConsumeEmbedField)
  198 {
  199   const char* src =
  200     "class iso C\n"
  201 
  202     "primitive P\n"
  203       "fun apply(c: C) => None\n"
  204 
  205     "actor Main\n"
  206       "embed c: C\n"
  207       "new create(env: Env) =>\n"
  208         "c = C\n"
  209         "P(consume c)";
  210 
  211   TEST_ERRORS_1(src,
  212     "can't consume a let or embed field");
  213 }
  214 
  215 TEST_F(ReferTest, ConsumeVarTry)
  216 {
  217   const char* src =
  218     "class iso C\n"
  219 
  220     "primitive P\n"
  221       "fun apply(c: C) ? => error\n"
  222 
  223     "actor Main\n"
  224       "new create(env: Env) =>\n"
  225         "var c = C\n"
  226         "try\n"
  227         "  P(consume c) ?"
  228         "end";
  229 
  230   TEST_COMPILE(src);
  231 }
  232 
  233 TEST_F(ReferTest, ConsumeVarReassignTry)
  234 {
  235   const char* src =
  236     "class iso C\n"
  237 
  238     "actor Main\n"
  239       "new create(env: Env) =>\n"
  240         "var c = C\n"
  241         "try\n"
  242         "  let d = consume c\n"
  243         "  c = consume d\n"
  244         "  error\n"
  245         "end\n";
  246 
  247   TEST_ERRORS_2(src,
  248     "can't reassign to a consumed identifier in a try expression unless it is"
  249     " reassigned in the same expression",
  250     "left side must be something that can be assigned to");
  251 }
  252 
  253 TEST_F(ReferTest, ConsumeVarFieldTry)
  254 {
  255   const char* src =
  256     "class iso C\n"
  257 
  258     "primitive P\n"
  259       "fun apply(c: C) ? => error\n"
  260 
  261     "actor Main\n"
  262       "var c: C\n"
  263       "new create(env: Env) =>\n"
  264         "c = C\n"
  265         "try\n"
  266         "  P(consume c) ?"
  267         "end";
  268 
  269   TEST_ERRORS_1(src,
  270     "consuming a field is only allowed if it is reassigned in the same"
  271     " expression");
  272 }
  273 
  274 TEST_F(ReferTest, WhileLoopConsumeLet)
  275 {
  276   const char* src =
  277     "class iso C\n"
  278 
  279     "primitive P\n"
  280       "fun apply(c: C) => None\n"
  281 
  282     "actor Main\n"
  283       "new create(env: Env) =>\n"
  284         "let c = C\n"
  285         "while true do\n"
  286           "P(consume c)\n"
  287         "end";
  288 
  289   TEST_ERRORS_1(src,
  290     "identifier 'c' is consumed when the loop exits");
  291 }
  292 
  293 TEST_F(ReferTest, WhileLoopConsumeLetInCondition)
  294 {
  295   const char* src =
  296     "class iso C\n"
  297 
  298     "primitive P\n"
  299       "fun apply(c: C) => None\n"
  300 
  301     "actor Main\n"
  302       "new create(env: Env) =>\n"
  303         "let c = C\n"
  304         "while P(consume c); true do\n"
  305           "None\n"
  306         "end";
  307 
  308   TEST_ERRORS_1(src,
  309     "can't consume from an outer scope in a loop condition");
  310 }
  311 
  312 TEST_F(ReferTest, WhileLoopDeclareLetAndUseOutside)
  313 {
  314   const char* src =
  315     "class val C\n"
  316       "new val create() => None\n"
  317 
  318     "primitive P\n"
  319       "fun apply(c: C) => None\n"
  320 
  321     "actor Main\n"
  322       "new create(env: Env) =>\n"
  323         "while let c1 = C; true do\n"
  324           "let c2 = C\n"
  325         "else\n"
  326           "let c3 = C\n"
  327         "end\n"
  328 
  329         "P(c1)\n"
  330         "P(c2)\n"
  331         "P(c3)";
  332 
  333   TEST_ERRORS_3(src,
  334     "can't find declaration of 'c1'",
  335     "can't find declaration of 'c2'",
  336     "can't find declaration of 'c3'");
  337 }
  338 
  339 TEST_F(ReferTest, RepeatLoopConsumeLet)
  340 {
  341   const char* src =
  342     "class iso C\n"
  343 
  344     "primitive P\n"
  345       "fun apply(c: C) => None\n"
  346 
  347     "actor Main\n"
  348       "new create(env: Env) =>\n"
  349         "let c = C\n"
  350         "repeat\n"
  351           "P(consume c)\n"
  352         "until false end";
  353 
  354   TEST_ERRORS_1(src,
  355     "identifier 'c' is consumed when the loop exits");
  356 }
  357 
  358 TEST_F(ReferTest, RepeatLoopConsumeLetInCondition)
  359 {
  360   const char* src =
  361     "class iso C\n"
  362 
  363     "primitive P\n"
  364       "fun apply(c: C) => None\n"
  365 
  366     "actor Main\n"
  367       "new create(env: Env) =>\n"
  368         "let c = C\n"
  369         "repeat\n"
  370           "None\n"
  371         "until\n"
  372           "P(consume c); false\n"
  373         "end";
  374 
  375   TEST_ERRORS_1(src,
  376     "can't consume from an outer scope in a loop condition");
  377 }
  378 
  379 TEST_F(ReferTest, RepeatLoopDeclareLetAndUseOutside)
  380 {
  381   const char* src =
  382     "class val C\n"
  383       "new val create() => None\n"
  384 
  385     "primitive P\n"
  386       "fun apply(c: C) => None\n"
  387 
  388     "actor Main\n"
  389       "new create(env: Env) =>\n"
  390         "repeat\n"
  391           "let c1 = C\n"
  392         "until\n"
  393           "let c2 = C; true\n"
  394         "else\n"
  395           "let c3 = C\n"
  396         "end\n"
  397 
  398         "P(c1)\n"
  399         "P(c2)\n"
  400         "P(c3)";
  401 
  402   TEST_ERRORS_3(src,
  403     "can't find declaration of 'c1'",
  404     "can't find declaration of 'c2'",
  405     "can't find declaration of 'c3'");
  406 }
  407 
  408 TEST_F(ReferTest, UndefinedVarValueNeeded)
  409 {
  410   const char* src =
  411     "class iso C\n"
  412 
  413     "actor Main\n"
  414       "new create(env: Env) => None\n"
  415       "fun apply(): C =>\n"
  416         "var c = C";
  417 
  418   TEST_ERRORS_1(src,
  419     "the left side is undefined but its value is used");
  420 }
  421 
  422 TEST_F(ReferTest, RepeatLoopDefineVarAndUseOutside)
  423 {
  424   const char* src =
  425     "actor Main\n"
  426       "new create(env: Env) =>\n"
  427         "var n: U8\n"
  428         "repeat\n"
  429           "n = 5\n"
  430         "until true end\n"
  431         "let n' = n";
  432 
  433   TEST_COMPILE(src);
  434 }
  435 
  436 TEST_F(ReferTest, RepeatLoopDefineVarAfterBreakAndUseOutside)
  437 {
  438   const char* src =
  439     "actor Main\n"
  440       "new create(env: Env) =>\n"
  441         "var n: U8\n"
  442         "repeat\n"
  443           "if true then break end\n"
  444           "n = 5\n"
  445         "until true end\n"
  446         "let n' = n";
  447 
  448   TEST_ERRORS_1(src,
  449     "can't use an undefined variable in an expression");
  450 }
  451 
  452 TEST_F(ReferTest, RepeatLoopDefineVarAfterNestedBreakAndUseOutside)
  453 {
  454   const char* src =
  455     "actor Main\n"
  456       "new create(env: Env) =>\n"
  457         "var n: U8\n"
  458         "repeat\n"
  459           "while true do break end\n"
  460           "n = 5\n"
  461         "until true end\n"
  462         "let n' = n";
  463 
  464   TEST_COMPILE(src);
  465 }
  466 
  467 TEST_F(ReferTest, RepeatLoopDefineVarAndUseInCondition)
  468 {
  469   // From issue #2784
  470   const char* src =
  471     "actor Main\n"
  472       "new create(env: Env) =>\n"
  473         "var n: U8\n"
  474         "repeat\n"
  475           "n = 5\n"
  476         "until (n > 2) end";
  477 
  478   TEST_COMPILE(src);
  479 }
  480 
  481 TEST_F(ReferTest, ConsumeVarFieldReassignSameExpressionConsumedReference)
  482 {
  483   const char* src =
  484     "class iso C\n"
  485 
  486     "actor Main\n"
  487       "var c: C\n"
  488       "new create(env: Env) =>\n"
  489         "c = C\n"
  490         "try\n"
  491         "  dostuff()?\n"
  492         "end\n"
  493 
  494       "fun ref dostuff() ? =>\n"
  495         "c = (consume c; consume c)\n"
  496         "error";
  497 
  498   TEST_ERRORS_1(src,
  499     "can't use a consumed local or field in an expression");
  500 }
  501 
  502 TEST_F(ReferTest, ConsumeVarFieldReassignSameExpressionReuse)
  503 {
  504   const char* src =
  505     "class iso C\n"
  506       "fun ref blah(d: C): C iso^ =>\n"
  507         "consume d\n"
  508 
  509     "actor Main\n"
  510       "var c: C\n"
  511       "new create(env: Env) =>\n"
  512         "c = C\n"
  513         "try\n"
  514         "  dostuff()?\n"
  515         "end\n"
  516 
  517       "fun ref dostuff() ? =>\n"
  518         "c = c.blah(consume c)\n"
  519         "error";
  520 
  521   TEST_ERRORS_1(src,
  522     "can't use a consumed local or field in an expression");
  523 }
  524 
  525 TEST_F(ReferTest, ConsumeVarFieldReassignSameExpressionReuseSubfield)
  526 {
  527   const char* src =
  528     "class iso C\n"
  529       "let s: String\n"
  530       "new iso create() => s = String\n"
  531 
  532     "actor Main\n"
  533       "var c: C\n"
  534       "new create(env: Env) =>\n"
  535         "c = C\n"
  536         "try\n"
  537         "  dostuff()?\n"
  538         "end\n"
  539 
  540       "fun ref blah(d: C, s: String): C iso^ =>\n"
  541         "consume d\n"
  542 
  543       "fun ref dostuff() ? =>\n"
  544         "c = blah(consume c, c.s)\n"
  545         "error";
  546 
  547   TEST_ERRORS_1(src,
  548     "can't use a consumed local or field in an expression");
  549 }
  550 
  551 TEST_F(ReferTest,
  552   ConsumeVarFieldVarSubfieldReassignSameExpressionConsumedReference)
  553 {
  554   const char* src =
  555     "class iso C\n"
  556       "var s: Array[U8] iso\n"
  557       "new iso create() => s = recover s.create() end\n"
  558 
  559     "actor Main\n"
  560       "var c: C\n"
  561       "new create(env: Env) =>\n"
  562         "c = C\n"
  563         "try\n"
  564         "  dostuff()?\n"
  565         "end\n"
  566 
  567       "fun ref dostuff() ? =>\n"
  568         "c.s = (consume c.s; consume c.s)\n"
  569         "error";
  570 
  571   TEST_ERRORS_1(src,
  572     "can't use a consumed local or field in an expression");
  573 }
  574 
  575 TEST_F(ReferTest, ConsumeVarFieldVarSubfieldReassignSameExpressionReuse)
  576 {
  577   const char* src =
  578     "class iso C\n"
  579       "var s: Array[U8] iso\n"
  580       "new iso create() => s = recover s.create() end\n"
  581 
  582     "actor Main\n"
  583       "var c: C\n"
  584       "new create(env: Env) =>\n"
  585         "c = C\n"
  586         "try\n"
  587         "  dostuff()?\n"
  588         "end\n"
  589 
  590       "fun ref blah(d: Array[U8] iso, n: USize): Array[U8] iso^ =>\n"
  591         "consume d\n"
  592 
  593       "fun ref dostuff() ? =>\n"
  594         "c.s = blah(consume c.s, c.s.size())\n"
  595         "error";
  596 
  597   TEST_ERRORS_1(src,
  598     "can't use a consumed local or field in an expression");
  599 }
  600 
  601 TEST_F(ReferTest,
  602   ConsumeLetFieldVarSubfieldReassignSameExpressionConsumedReference)
  603 {
  604   const char* src =
  605     "class iso C\n"
  606       "var s: Array[U8] iso\n"
  607       "new iso create() => s = recover s.create() end\n"
  608 
  609     "actor Main\n"
  610       "let c: C\n"
  611       "new create(env: Env) =>\n"
  612         "c = C\n"
  613         "try\n"
  614         "  dostuff()?\n"
  615         "end\n"
  616 
  617       "fun ref dostuff() ? =>\n"
  618         "c.s = (consume c.s; consume c.s)\n"
  619         "error";
  620 
  621   TEST_ERRORS_1(src,
  622     "can't use a consumed local or field in an expression");
  623 }
  624 
  625 TEST_F(ReferTest, ConsumeLetFieldVarSubfieldReassignSameExpressionReuse)
  626 {
  627   const char* src =
  628     "class iso C\n"
  629       "var s: Array[U8] iso\n"
  630       "new iso create() => s = recover s.create() end\n"
  631 
  632     "actor Main\n"
  633       "let c: C\n"
  634       "new create(env: Env) =>\n"
  635         "c = C\n"
  636         "try\n"
  637         "  dostuff()?\n"
  638         "end\n"
  639 
  640       "fun ref blah(d: Array[U8] iso, n: USize): Array[U8] iso^ =>\n"
  641         "consume d\n"
  642 
  643       "fun ref dostuff() ? =>\n"
  644         "c.s = blah(consume c.s, c.s.size())\n"
  645         "error";
  646 
  647   TEST_ERRORS_1(src,
  648     "can't use a consumed local or field in an expression");
  649 }
  650 
  651 TEST_F(ReferTest,
  652   ConsumeEmbedFieldVarSubfieldReassignSameExpressionConsumedReference)
  653 {
  654   const char* src =
  655     "class iso C\n"
  656       "var s: Array[U8] iso\n"
  657       "new iso create() => s = recover s.create() end\n"
  658 
  659     "actor Main\n"
  660       "embed c: C\n"
  661       "new create(env: Env) =>\n"
  662         "c = C\n"
  663         "try\n"
  664         "  dostuff()?\n"
  665         "end\n"
  666 
  667       "fun ref dostuff() ? =>\n"
  668         "c.s = (consume c.s; consume c.s)\n"
  669         "error";
  670 
  671   TEST_ERRORS_1(src,
  672     "can't use a consumed local or field in an expression");
  673 }
  674 
  675 TEST_F(ReferTest, ConsumeEmbedFieldVarSubfieldReassignSameExpressionReuse)
  676 {
  677   const char* src =
  678     "class iso C\n"
  679       "var s: Array[U8] iso\n"
  680       "new iso create() => s = recover s.create() end\n"
  681 
  682     "actor Main\n"
  683       "embed c: C\n"
  684       "new create(env: Env) =>\n"
  685         "c = C\n"
  686         "try\n"
  687         "  dostuff()?\n"
  688         "end\n"
  689 
  690       "fun ref blah(d: Array[U8] iso, n: USize): Array[U8] iso^ =>\n"
  691         "consume d\n"
  692 
  693       "fun ref dostuff() ? =>\n"
  694         "c.s = blah(consume c.s, c.s.size())\n"
  695         "error";
  696 
  697   TEST_ERRORS_1(src,
  698     "can't use a consumed local or field in an expression");
  699 }
  700 
  701 TEST_F(ReferTest,
  702   ConsumeVarLocalVarSubfieldReassignSameExpressionConsumedReference)
  703 {
  704   const char* src =
  705     "class iso C\n"
  706       "var s: Array[U8] iso\n"
  707       "new iso create() => s = recover s.create() end\n"
  708 
  709     "actor Main\n"
  710       "new create(env: Env) =>\n"
  711         "try\n"
  712         "  dostuff()?\n"
  713         "end\n"
  714 
  715       "fun ref dostuff() ? =>\n"
  716         "var c: C = C\n"
  717         "c.s = (consume c.s; consume c.s)\n"
  718         "error";
  719 
  720   TEST_ERRORS_1(src,
  721     "can't use a consumed local or field in an expression");
  722 }
  723 
  724 TEST_F(ReferTest, ConsumeVarLocalVarSubfieldReassignSameExpressionReuse)
  725 {
  726   const char* src =
  727     "class iso C\n"
  728       "var s: Array[U8] iso\n"
  729       "new iso create() => s = recover s.create() end\n"
  730 
  731     "actor Main\n"
  732       "new create(env: Env) =>\n"
  733         "try\n"
  734         "  dostuff()?\n"
  735         "end\n"
  736 
  737       "fun ref blah(d: Array[U8] iso, n: USize): Array[U8] iso^ =>\n"
  738         "consume d\n"
  739 
  740       "fun ref dostuff() ? =>\n"
  741         "var c: C = C\n"
  742         "c.s = blah(consume c.s, c.s.size())\n"
  743         "error";
  744 
  745   TEST_ERRORS_1(src,
  746     "can't use a consumed local or field in an expression");
  747 }
  748 
  749 TEST_F(ReferTest,
  750   ConsumeLetLocalVarSubfieldReassignSameExpressionConsumedReference)
  751 {
  752   const char* src =
  753     "class iso C\n"
  754       "var s: Array[U8] iso\n"
  755       "new iso create() => s = recover s.create() end\n"
  756 
  757     "actor Main\n"
  758       "new create(env: Env) =>\n"
  759         "try\n"
  760         "  dostuff()?\n"
  761         "end\n"
  762 
  763       "fun ref dostuff() ? =>\n"
  764         "let c: C = C\n"
  765         "c.s = (consume c.s; consume c.s)\n"
  766         "error";
  767 
  768   TEST_ERRORS_1(src,
  769     "can't use a consumed local or field in an expression");
  770 }
  771 
  772 TEST_F(ReferTest, ConsumeLetLocalVarSubfieldReassignSameExpressionReuse)
  773 {
  774   const char* src =
  775     "class iso C\n"
  776       "var s: Array[U8] iso\n"
  777       "new iso create() => s = recover s.create() end\n"
  778 
  779     "actor Main\n"
  780       "new create(env: Env) =>\n"
  781         "try\n"
  782         "  dostuff()?\n"
  783         "end\n"
  784 
  785       "fun ref blah(d: Array[U8] iso, n: USize): Array[U8] iso^ =>\n"
  786         "consume d\n"
  787 
  788       "fun ref dostuff() ? =>\n"
  789         "let c: C = C\n"
  790         "c.s = blah(consume c.s, c.s.size())\n"
  791         "error";
  792 
  793   TEST_ERRORS_1(src,
  794     "can't use a consumed local or field in an expression");
  795 }
  796 
  797 TEST_F(ReferTest, ConsumeParamVarSubfieldReassignSameExpressionConsumedReference)
  798 {
  799   const char* src =
  800     "class iso C\n"
  801       "var s: Array[U8] iso\n"
  802       "new iso create() => s = recover s.create() end\n"
  803 
  804     "actor Main\n"
  805       "new create(env: Env) =>\n"
  806         "try\n"
  807         "  dostuff(C)?\n"
  808         "end\n"
  809 
  810       "fun ref dostuff(c: C) ? =>\n"
  811         "c.s = (consume c.s; consume c.s)\n"
  812         "error";
  813 
  814   TEST_ERRORS_1(src,
  815     "can't use a consumed local or field in an expression");
  816 }
  817 
  818 TEST_F(ReferTest, ConsumeParamVarSubfieldReassignSameExpressionReuse)
  819 {
  820   const char* src =
  821     "class iso C\n"
  822       "var s: Array[U8] iso\n"
  823       "new iso create() => s = recover s.create() end\n"
  824 
  825     "actor Main\n"
  826       "new create(env: Env) =>\n"
  827         "try\n"
  828         "  dostuff(C)?\n"
  829         "end\n"
  830 
  831       "fun ref blah(d: Array[U8] iso, n: USize): Array[U8] iso^ =>\n"
  832         "consume d\n"
  833 
  834       "fun ref dostuff(c: C) ? =>\n"
  835         "c.s = blah(consume c.s, c.s.size())\n"
  836         "error";
  837 
  838   TEST_ERRORS_1(src,
  839     "can't use a consumed local or field in an expression");
  840 }