diff --git a/src/language.yacc b/src/language.yacc
index 946ae0ad7784dae3e5b2b9cbf296ab913b35806d..4ee4dde4dd8ede1a261bfe9a8a264e3dc6ca31e0 100644
--- a/src/language.yacc
+++ b/src/language.yacc
@@ -1336,7 +1336,7 @@ basic_type:
   | TOK_MAPPING_ID  opt_mapping_type  {}
   | TOK_FUNCTION_ID opt_function_type {}
   | TOK_OBJECT_ID   opt_object_type   {}
-  | TOK_PROGRAM_ID  opt_object_type   { push_type(T_PROGRAM); }
+  | TOK_PROGRAM_ID  opt_program_type  { push_type(T_PROGRAM); }
   | TOK_ARRAY_ID    opt_array_type    { push_type(T_ARRAY); }
   | TOK_MULTISET_ID opt_array_type    { push_type(T_MULTISET); }
   | TOK_ATTRIBUTE_ID '(' string_constant ',' type7 ')'
@@ -1589,6 +1589,15 @@ opt_object_type:  /* Empty */ { push_object_type(0, 0); }
   }
   ;
 
+opt_program_type:  /* Empty */ { push_object_type(0, 0); }
+  | '(' type4 ')'
+  | '(' error ')'
+  {
+    push_object_type(0, 0);
+    yyerror("Invalid program subtype.");
+  }
+  ;
+
 opt_function_type: '('
   {
     type_stack_mark();
diff --git a/src/pike_types.c b/src/pike_types.c
index 93bc5cde9e54ca12d70d2d52f581156b8ae1c47d..016981dea73a15f04181225a999b9abc5a4f34ac 100644
--- a/src/pike_types.c
+++ b/src/pike_types.c
@@ -930,11 +930,16 @@ void debug_push_type(unsigned int type)
 					  PT_COPY_BOTH);
     break;
 
+  case T_PROGRAM:
+    if ((*Pike_compiler->type_stackp)->type != T_OBJECT) {
+      /* Not a program type, convert it to a type type. */
+      type = T_TYPE;
+    }
+    /* FALL_THROUGH */
   case T_ARRAY:
   case T_MULTISET:
   case T_NOT:
   case T_TYPE:
-  case T_PROGRAM:
   case T_STRING:
     /* Make a new type of the top type, and put it in car. */
     *Pike_compiler->type_stackp = mk_type(type,