Browse Source

Check for empty generic declaration list

Ginger Bill 8 years ago
parent
commit
e6a206a430
3 changed files with 15 additions and 5 deletions
  1. 0 4
      code/demo.odin
  2. 7 0
      core/strings.odin
  3. 8 1
      src/parser.cpp

+ 0 - 4
code/demo.odin

@@ -14,10 +14,6 @@ import (
 	"utf16.odin";
 	"utf16.odin";
 )
 )
 
 
-const (
-	X = 123;
-	Y = 432;
-)
 
 
 proc main() {
 proc main() {
 	proc(s: string){
 	proc(s: string){

+ 7 - 0
core/strings.odin

@@ -1,3 +1,10 @@
+proc new_string(s: string) -> string {
+	var c = make([]u8, len(s)+1);
+	copy(c, []u8(s));
+	c[len(s)] = 0;
+	return string(c[0..<len(s)]);
+}
+
 proc new_c_string(s: string) -> ^u8 {
 proc new_c_string(s: string) -> ^u8 {
 	var c = make([]u8, len(s)+1);
 	var c = make([]u8, len(s)+1);
 	copy(c, []u8(s));
 	copy(c, []u8(s));

+ 8 - 1
src/parser.cpp

@@ -2567,11 +2567,19 @@ AstNode *parse_gen_decl(AstFile *f, Token token, ParseSpecFunc *func) {
 			expect_semicolon(f, spec);
 			expect_semicolon(f, spec);
 		}
 		}
 		close = expect_token(f, Token_CloseParen);
 		close = expect_token(f, Token_CloseParen);
+		if (f->curr_token.pos.line == close.pos.line ||
+		    open.pos.line == close.pos.line) {
+			expect_semicolon(f, NULL);
+		}
 	} else {
 	} else {
 		array_init(&specs, heap_allocator(), 1);
 		array_init(&specs, heap_allocator(), 1);
 		array_add(&specs, func(f, token));
 		array_add(&specs, func(f, token));
 	}
 	}
 
 
+	if (specs.count == 0) {
+		syntax_error(token, "Empty %.*s declaration list", LIT(token_strings[token.kind]));
+	}
+
 	AstNode *decl = ast_gen_decl(f, token, open, close, specs);
 	AstNode *decl = ast_gen_decl(f, token, open, close, specs);
 	if (token.kind == Token_let) {
 	if (token.kind == Token_let) {
 		decl->GenDecl.flags |= VarDeclFlag_immutable;
 		decl->GenDecl.flags |= VarDeclFlag_immutable;
@@ -2790,7 +2798,6 @@ AstNode *parse_decl(AstFile *f) {
 
 
 	Token token = f->curr_token;
 	Token token = f->curr_token;
 	next_token(f);
 	next_token(f);
-
 	return parse_gen_decl(f, token, func);
 	return parse_gen_decl(f, token, func);
 }
 }