]> Nishi Git Mirror - gwion.git/commitdiff
:art: Nonnull not (!) checking
authorJérémie Astor <fennecdjay@gmail.com>
Wed, 9 Dec 2020 01:50:43 +0000 (02:50 +0100)
committerJérémie Astor <fennecdjay@gmail.com>
Wed, 9 Dec 2020 01:50:43 +0000 (02:50 +0100)
src/lib/object_op.c

index 4e868d719b9639d590021b17117c5375b563bf52..639a894a052c9ff045c0357a0bd27dbb8d8c8c97 100644 (file)
@@ -110,6 +110,14 @@ static OP_EMIT(opem_implicit_null2obj) {
   return (Instr)GW_OK;
 }
 
+static OP_CHECK(opck_object_not) {
+  const Exp_Unary* unary = (Exp_Unary*)data;
+  const Type t = unary->exp->info->type;
+  if(tflag(t, tflag_nonnull))
+    ERR_N(unary->exp->pos, "expression is known to be nonnull");
+  return unary->exp->info->type;
+}
+
 ANN /*static*/ Type scan_class(const Env env, const Type t, const Type_Decl* td);
 
 static Type opck_object_scan(const Env env, const struct TemplateScan *ts) {
@@ -461,6 +469,7 @@ GWION_IMPORT(object_op) {
   GWI_BB(gwi_oper_end(gwi, "$", NULL))
   GWI_BB(gwi_oper_ini(gwi, NULL, "Object", "bool"))
   GWI_BB(gwi_oper_add(gwi, opck_unary_meta2))
+  GWI_BB(gwi_oper_add(gwi, opck_object_not))
   GWI_BB(gwi_oper_end(gwi, "!", IntNot))
   GWI_BB(gwi_oper_ini(gwi, "@Compound", NULL, NULL))
   GWI_BB(gwi_oper_add(gwi, opck_struct_scan))