From: Jérémie Astor <fennecdjay@gmail.com>
Date: Wed, 6 Apr 2022 16:13:05 +0000 (+0200)
Subject: :bug: Add error message to env_storage (thanks quibono :smile:)
X-Git-Tag: nightly~341
X-Git-Url: http://10.11.0.4:5575/?a=commitdiff_plain;h=8ab3e88510c765c053fc3d3d52c547e22479cb28;p=gwion.git

:bug: Add error message to env_storage (thanks quibono :smile:)
---

diff --git a/src/env/env_utils.c b/src/env/env_utils.c
index d23f9f69..6e786b87 100644
--- a/src/env/env_utils.c
+++ b/src/env/env_utils.c
@@ -9,19 +9,21 @@
 ANN m_bool env_access(const Env env, const ae_flag flag, const loc_t pos) {
   if (env->scope->depth) {
     if (GET(flag, ae_flag_global))
-      ERR_B(pos, _("'global' can only be used at %s scope."),
+      ERR_B(pos, _("`{G}global{0}` can only be used at %s scope."),
             GET(flag, ae_flag_global) && !env->class_def ? "file" : "class")
   }
   if ((GET(flag, ae_flag_static) || GET(flag, ae_flag_private) ||
        GET(flag, ae_flag_protect)) &&
       (!env->class_def || env->scope->depth))
-    ERR_B(pos, _("static/private/protect can only be used at class scope."))
+    ERR_B(pos, _("`{G}static/private/protect{0}` can only be used at class scope."))
   return GW_OK;
 }
 
 ANN m_bool env_storage(const Env env, ae_flag flag, const loc_t pos) {
   CHECK_BB(env_access(env, flag, pos));
-  return !(env->class_def && GET(flag, ae_flag_global)) ? GW_OK : GW_ERROR;
+  if(env->class_def && GET(flag, ae_flag_global))
+    ERR_B(pos, _("`{G}global{0}` at class scope only valid for function pointers"));
+  return GW_OK;
 }
 #undef GET
 
diff --git a/src/parse/scan1.c b/src/parse/scan1.c
index a18ccf29..2a31cf94 100644
--- a/src/parse/scan1.c
+++ b/src/parse/scan1.c
@@ -234,9 +234,14 @@ ANN static m_bool scan1_exp_if(const Env env, const Exp_If *exp_if) {
 }
 
 ANN static inline m_bool scan1_exp_unary(const restrict Env env,
-                                         const Exp_Unary *  unary) {
+                                         Exp_Unary *const  unary) {
   if (unary->unary_type == unary_code) {
-    RET_NSPC(scan1_stmt(env, unary->code))
+    const loc_t pos = exp_self(unary)->pos;
+    const Symbol sym = lambda_name(env->gwion->st, pos.first);
+    Exp lambda = new_exp_lambda(env->gwion->mp, sym, NULL, unary->code, pos);
+    mp_free(env->gwion->mp, Stmt, unary->code);
+    unary->exp = new_exp_call(env->gwion->mp, lambda, NULL, pos);
+    unary->unary_type = unary_exp;
   }
   return unary->unary_type == unary_exp ? scan1_exp(env, unary->exp) : GW_OK;
 }
diff --git a/src/parse/scan2.c b/src/parse/scan2.c
index d4971301..1a8c663e 100644
--- a/src/parse/scan2.c
+++ b/src/parse/scan2.c
@@ -179,9 +179,7 @@ ANN static inline m_bool scan2_exp_if(const Env env, const Exp_If *exp_if) {
 }
 
 ANN static m_bool scan2_exp_unary(const Env env, const Exp_Unary *unary) {
-  if (unary->unary_type == unary_code) {
-    RET_NSPC(scan2_stmt(env, unary->code))
-  } else if (unary->unary_type == unary_exp)
+  if (unary->unary_type == unary_exp)
     return scan2_exp(env, unary->exp);
   return GW_OK;
 }
diff --git a/tests/error/global_in_class.gw b/tests/error/global_in_class.gw
new file mode 100644
index 00000000..51ef9b8b
--- /dev/null
+++ b/tests/error/global_in_class.gw
@@ -0,0 +1,4 @@
+#! [contains] at class scope only valid for function pointers
+class global C {
+  var global Event ev;
+}
diff --git a/tests/error/invalid_global_class.gw b/tests/error/invalid_global_class.gw
index d9841a82..fe8da919 100644
--- a/tests/error/invalid_global_class.gw
+++ b/tests/error/invalid_global_class.gw
@@ -1,4 +1,4 @@
-#! [contains] 'global' can only be used at class scope
+#! [contains] can only be used at class scope
 class C {
   {
     var global int i;
diff --git a/tests/error/invalid_global_file.gw b/tests/error/invalid_global_file.gw
index 14981d13..93a9ec7c 100644
--- a/tests/error/invalid_global_file.gw
+++ b/tests/error/invalid_global_file.gw
@@ -1,4 +1,4 @@
-#! [contains] 'global' can only be used at file scope
+#! [contains] can only be used at file scope
 {
 var global int i;
 }
diff --git a/tests/error/lambda_mismatch1.gw b/tests/error/lambda_mismatch1.gw
index 5635d4cf..1a35c4ed 100644
--- a/tests/error/lambda_mismatch1.gw
+++ b/tests/error/lambda_mismatch1.gw
@@ -1,2 +1,2 @@
-#! [contains] argument number does not match for lambda
+#! [contains] not enough arguments for lambda
 \a b { <<< a, " ", b >>>; }(1);