From a1b4af896639ea8592abb32e7d797cf206656cc9 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Astor?= Date: Wed, 9 Dec 2020 02:50:43 +0100 Subject: [PATCH] :art: Nonnull not (!) checking --- src/lib/object_op.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/lib/object_op.c b/src/lib/object_op.c index 4e868d71..639a894a 100644 --- a/src/lib/object_op.c +++ b/src/lib/object_op.c @@ -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)) -- 2.43.0