Changeset: b5cd7ce72c37 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/b5cd7ce72c37
Modified Files:
        sql/server/rel_psm.c
        sql/test/miscellaneous/Tests/simple_selects.test
Branch: Jul2021
Log Message:

My bad, enfore return statements after while statements (see test entry)


diffs (75 lines):

diff --git a/sql/server/rel_psm.c b/sql/server/rel_psm.c
--- a/sql/server/rel_psm.c
+++ b/sql/server/rel_psm.c
@@ -585,29 +585,6 @@ rel_select_with_into(sql_query *query, s
        return rel_psm_block(query->sql->sa, reslist);
 }
 
-static int while_exps_find_one_return(list *l);
-
-static int
-while_exp_find_one_return(sql_exp *e)
-{
-       if (e->flag & PSM_RETURN)
-               return 1;
-       if (e->flag & PSM_WHILE)
-               return while_exps_find_one_return(e->r);
-       if (e->flag & PSM_IF)
-               return while_exps_find_one_return(e->r) || (e->f && 
while_exps_find_one_return(e->f));
-       return 0;
-}
-
-static int
-while_exps_find_one_return(list *l)
-{
-       int res = 0;
-       for (node *n = l->h ; n && !res; n = n->next)
-               res |= while_exp_find_one_return(n->data);
-       return res;
-}
-
 static int has_return( list *l );
 
 static int
@@ -618,8 +595,6 @@ exp_has_return(sql_exp *e)
                        return 1;
                if (e->flag & PSM_IF) /* for if, both sides must exist and both 
must have a return */
                        return has_return(e->r) && e->f && has_return(e->f);
-               if (e->flag & PSM_WHILE) /* for while, at least one of the 
statements must have a return */
-                       return while_exps_find_one_return(e->r);
        }
        return 0;
 }
diff --git a/sql/test/miscellaneous/Tests/simple_selects.test 
b/sql/test/miscellaneous/Tests/simple_selects.test
--- a/sql/test/miscellaneous/Tests/simple_selects.test
+++ b/sql/test/miscellaneous/Tests/simple_selects.test
@@ -753,7 +753,7 @@ select ups()
 2
 
 statement ok
-create or replace function ups() returns int begin while 1 = 1 do if null is 
null then return 1; else return 2; end if; end while; end
+create or replace function ups() returns int begin while 1 = 1 do if null is 
null then return 1; else return 2; end if; end while; return 1; end
 
 query I rowsort
 select ups()
@@ -761,7 +761,7 @@ select ups()
 1
 
 statement ok
-create or replace function ups() returns int begin declare a int; set a = 2; 
while a < 2 do if null is null then return 3; else set a = 2; end if; end 
while; end
+create or replace function ups() returns int begin declare a int; set a = 2; 
while a < 2 do if null is null then return 3; else set a = 2; end if; end 
while; return 3; end
 
 query I rowsort
 select ups()
@@ -854,3 +854,11 @@ 3
 
 statement ok
 rollback
+
+statement error CREATE FUNCTION: missing return statement
+CREATE FUNCTION wrongfunc() RETURNS INT
+BEGIN
+       WHILE (FALSE) DO
+               RETURN 1;
+       END WHILE;
+END
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to