← Back to team overview

zorba-coders team mailing list archive

[Merge] lp:~zorba-coders/zorba/hof-next into lp:zorba

 

Markos Zaharioudakis has proposed merging lp:~zorba-coders/zorba/hof-next into lp:zorba.

Commit message:
1. Fixed bug concerning the raising of XPTY0018 in the presence of function items.
2. hof optimization: avoid function coersion if possible.


Requested reviews:
  Markos Zaharioudakis (markos-za)

For more details, see:
https://code.launchpad.net/~zorba-coders/zorba/hof-next/+merge/159569

1. Fixed bug concerning the raising of XPTY0018 in the presence of function items.
2. hof optimization: avoid function coersion if possible.
-- 
https://code.launchpad.net/~zorba-coders/zorba/hof-next/+merge/159569
Your team Zorba Coders is subscribed to branch lp:zorba.
=== modified file 'src/compiler/translator/translator.cpp'
--- src/compiler/translator/translator.cpp	2013-04-16 20:06:08 +0000
+++ src/compiler/translator/translator.cpp	2013-04-18 08:52:28 +0000
@@ -1506,16 +1506,21 @@
     }
     else if (paramType->type_kind() == XQType::FUNCTION_TYPE_KIND)
     {
-      // function coercion
-      argExpr = wrap_in_coercion(paramType, argExpr, loc);
-
-      xqtref_t cardType = tm->create_any_item_type(paramType->get_quantifier());
-
-      argExpr = wrap_in_type_match(argExpr,
-                                   cardType,
-                                   loc,
-                                   TREAT_FUNC_PARAM,
-                                   func->getName());
+      xqtref_t argType = argExpr->get_return_type();
+
+      if (!TypeOps::is_subtype(tm, *argType, *paramType, loc))
+      {
+        // function coercion
+        argExpr = wrap_in_coercion(paramType, argExpr, loc);
+
+        xqtref_t cardType = tm->create_any_item_type(paramType->get_quantifier());
+
+        argExpr = wrap_in_type_match(argExpr,
+                                     cardType,
+                                     loc,
+                                     TREAT_FUNC_PARAM,
+                                     func->getName());
+      }
     }
     else
     {

=== modified file 'src/runtime/core/sequencetypes.cpp'
--- src/runtime/core/sequencetypes.cpp	2013-04-08 19:44:58 +0000
+++ src/runtime/core/sequencetypes.cpp	2013-04-18 08:52:28 +0000
@@ -813,16 +813,16 @@
 
   if (CONSUME(result, 0))
   {
-    state->atomics = result->isAtomic();
+    state->atomics = !result->isNode();
 
     STACK_PUSH(true, state);
 
     while (CONSUME(result, 0))
     {
-      if (state->atomics != result->isAtomic())
+      if (state->atomics == result->isNode())
         throw XQUERY_EXCEPTION(err::XPTY0018, ERROR_LOC(loc));
 
-      STACK_PUSH (true, state);
+      STACK_PUSH(true, state);
     }
   }
 

=== modified file 'src/store/naive/node_iterators.cpp'
--- src/store/naive/node_iterators.cpp	2013-02-07 17:24:36 +0000
+++ src/store/naive/node_iterators.cpp	2013-04-18 08:52:28 +0000
@@ -207,7 +207,7 @@
     if (!theInput->next(result))
       return false;
 
-    if (!result->isAtomic())
+    if (result->isNode())
       throw XQUERY_EXCEPTION(err::XPTY0018);
 
     return true;
@@ -216,7 +216,7 @@
   if (!theInput->next(result))
     return false;
 
-  if (result->isAtomic())
+  if (!result->isNode())
   {
     if (theNodeMode)
       throw XQUERY_EXCEPTION(err::XPTY0018);
@@ -236,7 +236,7 @@
       if (!theInput->next(result))
         return false;
 
-      if (result->isAtomic())
+      if (!result->isNode())
         throw XQUERY_EXCEPTION(err::XPTY0018);
     }
   }
@@ -404,7 +404,7 @@
     if (!theInput->next(result))
       return false;
 
-    if (!result->isAtomic())
+    if (result->isNode())
       throw XQUERY_EXCEPTION(err::XPTY0018);
 
     return true;
@@ -417,7 +417,7 @@
       if (!theInput->next(result))
         break;
 
-      if (result->isAtomic() || result->isFunction())
+      if (!result->isNode())
       {
         if (theNodeMode)
           throw XQUERY_EXCEPTION(err::XPTY0018);


Follow ups