Browse Source

Fixed a crash bug reported by fuzzy test. Unit test added.

Marco Bambini 8 years ago
parent
commit
74c051b468

+ 6 - 0
src/compiler/gravity_semacheck2.c

@@ -821,6 +821,12 @@ static void visit_class_decl (gvisitor_t *self, gnode_class_decl_t *node) {
 	// set class enclosing (can be globals, a class or a function)
 	node->env = top;
 	
+    // sanity check on class name
+    if (string_cmp(node->identifier, CLASS_CONSTRUCTOR_NAME) == 0) {
+        REPORT_ERROR(node, "%s is a special name and cannot be used as class identifier.", CLASS_CONSTRUCTOR_NAME);
+        return;
+    }
+    
 	// check superclass
 	if (node->superclass) {
         // get super class identifier and reset the field (so in case of error it cannot be accessed)

+ 17 - 0
test/fuzzy/2017-06-02/id_000002_sig_11_src_002990_op_ext_AO_pos_184.gravity

@@ -0,0 +1,17 @@
+#unittest {
+	name: "Subclass oveurn V1+b2;
+	}
+}
+
+class foo:bar {vár eb07,b01ccccccccccccccccccccccccccccccccccccccccccccccccccccccccde and super access.";
+	result: 4666;
+};
+
+class bar:Int {
+	func f1() {ret	}
+}
+
+class foo:bar {
+	var e1 = 10;
+	var eb07,b0cccccgccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc020;
+}

+ 32 - 0
test/fuzzy/2017-06-02/id_000003_sig_11_src_003182_op_ext_AO_pos_196.gravity

@@ -0,0 +1,32 @@
+#unittest {
+	name: "Simple closure.apply internal i}it.";
+	error: NONE;
+	result:90000;
+};
+
+// class declarations
+class bar {
+
//ss var
+	static var a1 = 10;
+	static var a2 = 20;// clasations
+class init{
+	//ss var
+	static var a1 = 10;
+	static var a2 = 20;// class const
+	static var b1 = 100;
+	static var b2 = 200;
+	
+	// instance var
+	var c1 = 1000;
+	var c2 = 2000;
+	
+	// instancest
+	var d1 = 10000;
+	var d2 = 22+d1+d2;
+	}
+}
+
+func main() {
+	var n1	var n2 = bar().f2();	// 33000
+	return n1*n2;
+}