Index: includes/theme.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/theme.inc,v
retrieving revision 1.533
diff -u -p -r1.533 theme.inc
--- includes/theme.inc	9 Oct 2009 16:33:13 -0000	1.533
+++ includes/theme.inc	11 Oct 2009 08:07:14 -0000
@@ -779,20 +779,23 @@ function theme($hook, $variables = array
   }
 
   // If a renderable array is passed as $variables, then set $variables to
-  // what's expected by the theme hook. If the theme hook expects a single
-  // argument, set the renderable array as that argument. If the theme hook
-  // expects multiple arguments, set the properties of the renderable array as
-  // those arguments.
+  // what's expected by the theme hook. If the theme hook expects multiple
+  // arguments, use the properties of the renderable array as those arguments.
+  // If the theme hook expects a single argument, make a best guess as to
+  // whether the theme hook wants the renderable array itself or its property
+  // as that argument.
+  // @todo: For D8, fix it so that guessing isn't necessary.
+  // @see http://drupal.org/node/600974
   if (isset($variables['#theme']) || isset($variables['#theme_wrappers'])) {
     $element = $variables;
     $variables = array();
     $n = count($info['arguments']);
-    if ($n == 1) {
-      $arg_keys = array_keys($info['arguments']);
-      $variables[$arg_keys[0]] = $element;
+    $arg_names = array_keys($info['arguments']);
+    if ($n == 1 && (isset($element['#type']) || !isset($element['#' . $arg_names[0]]))) {
+      $variables[$arg_names[0]] = $element;
     }
-    elseif ($n > 1) {
-      foreach ($info['arguments'] as $name => $default) {
+    else {
+      foreach ($arg_names as $name) {
         if (isset($element["#$name"])) {
           $variables[$name] = $element["#$name"];
         }
