]> Nishi Git Mirror - gwion.git/commitdiff
:art: Error message on return type mismatch
authorfennecdjay <astor.jeremie@wanadoo.fr>
Sun, 20 Oct 2019 14:53:25 +0000 (16:53 +0200)
committerfennecdjay <astor.jeremie@wanadoo.fr>
Sun, 20 Oct 2019 14:53:25 +0000 (16:53 +0200)
src/parse/check.c
tests/error/return_expected.gw [new file with mode: 0644]

index 6942acf44686b3f45753b98aa394b7eb71597096..0b208e4ecb5c3c53054ca26967ca75944f29a604 100644 (file)
@@ -1086,8 +1086,13 @@ ANN static m_bool check_stmt_return(const Env env, const Stmt_Exp stmt) {
   }
   if(isa(ret_type, env->func->def->base->ret_type) > 0)
     return GW_OK;
-  if(stmt->val)
-    return check_implicit(env, stmt->val, env->func->def->base->ret_type);
+  if(stmt->val) {
+    const m_bool ret = check_implicit(env, stmt->val, env->func->def->base->ret_type);
+    if(ret > 0)
+      return ret;
+    ERR_B(stmt_self(stmt)->pos, _("invalid return type: got '%s', expected '%s'"),
+        ret_type->name, env->func->def->base->ret_type->name)
+  }
   if(isa(env->func->def->base->ret_type, env->gwion->type[et_void]) > 0)
     return GW_OK;
   ERR_B(stmt_self(stmt)->pos, _("missing value for return statement"))
diff --git a/tests/error/return_expected.gw b/tests/error/return_expected.gw
new file mode 100644 (file)
index 0000000..8306dac
--- /dev/null
@@ -0,0 +1,2 @@
+#! [contains] invalid return type
+fun int test() { return me; }