Browse Source

Fix parsing bug with procedure types in return values

Ginger Bill 8 years ago
parent
commit
eab23cd5b7
1 changed files with 23 additions and 21 deletions
  1. 23 21
      src/parser.cpp

+ 23 - 21
src/parser.cpp

@@ -2295,28 +2295,30 @@ AstNode *parse_operand(AstFile *f, bool lhs) {
 
 
 		if (allow_token(f, Token_Undef)) {
 		if (allow_token(f, Token_Undef)) {
 			return ast_proc_lit(f, type, nullptr, tags, link_name);
 			return ast_proc_lit(f, type, nullptr, tags, link_name);
-		} else if (f->curr_token.kind == Token_OpenBrace) {
-			if ((tags & ProcTag_foreign) != 0) {
-				syntax_error(token, "A procedure tagged as `#foreign` cannot have a body");
-			}
-			AstNode *curr_proc = f->curr_proc;
-			AstNode *body = nullptr;
-			f->curr_proc = type;
-			body = parse_body(f);
-			f->curr_proc = curr_proc;
-
-			return ast_proc_lit(f, type, body, tags, link_name);
-		} else if (allow_token(f, Token_do)) {
-			if ((tags & ProcTag_foreign) != 0) {
-				syntax_error(token, "A procedure tagged as `#foreign` cannot have a body");
-			}
-			AstNode *curr_proc = f->curr_proc;
-			AstNode *body = nullptr;
-			f->curr_proc = type;
-			body = convert_stmt_to_body(f, parse_stmt(f));
-			f->curr_proc = curr_proc;
+		} else if (!f->allow_type || f->expr_level >= 0) {
+			if (f->curr_token.kind == Token_OpenBrace) {
+				if ((tags & ProcTag_foreign) != 0) {
+					syntax_error(token, "A procedure tagged as `#foreign` cannot have a body");
+				}
+				AstNode *curr_proc = f->curr_proc;
+				AstNode *body = nullptr;
+				f->curr_proc = type;
+				body = parse_body(f);
+				f->curr_proc = curr_proc;
+
+				return ast_proc_lit(f, type, body, tags, link_name);
+			} else if (allow_token(f, Token_do)) {
+				if ((tags & ProcTag_foreign) != 0) {
+					syntax_error(token, "A procedure tagged as `#foreign` cannot have a body");
+				}
+				AstNode *curr_proc = f->curr_proc;
+				AstNode *body = nullptr;
+				f->curr_proc = type;
+				body = convert_stmt_to_body(f, parse_stmt(f));
+				f->curr_proc = curr_proc;
 
 
-			return ast_proc_lit(f, type, body, tags, link_name);
+				return ast_proc_lit(f, type, body, tags, link_name);
+			}
 		}
 		}
 
 
 		if ((tags & ProcTag_foreign) != 0) {
 		if ((tags & ProcTag_foreign) != 0) {