Ver código fonte

disallow usage of super as value (closes #2750)

Simon Krajewski 11 anos atrás
pai
commit
5c31c27605
3 arquivos alterados com 40 adições e 1 exclusões
  1. 5 1
      extra/CHANGES.txt
  2. 34 0
      tests/unit/issues/Issue2750.hx
  3. 1 0
      typer.ml

+ 5 - 1
extra/CHANGES.txt

@@ -1,8 +1,12 @@
 2014-??-??: 3.1.2
 
+	Bugfixes:
+
+	all : properly disallowed usage of super as value
+
 	General improvements and optimizations:
 
-	all : cache file exist checks to speed up compilations with a lot of class paths
+	all : cached file exist checks to speed up compilations with a lot of class paths
 
 2014-03-15: 3.1.1
 

+ 34 - 0
tests/unit/issues/Issue2750.hx

@@ -0,0 +1,34 @@
+package unit.issues;
+import unit.Test;
+
+private class Parent extends Test {
+    function new() {
+		super();
+	}
+	
+	function foo() {
+		return 1;
+	}
+}
+
+class Issue2750 extends Parent {
+	function test() {
+		new Issue2750();
+	}
+	
+    public function new() {
+        super();
+		eq(3, foo());
+		call(this);
+		t(unit.TestType.typeError(var x = super));
+		t(unit.TestType.typeError(call(super)));
+		t(unit.TestType.typeError({ field: super }));
+		t(unit.TestType.typeError([super]));
+    }
+	
+	override function foo() {
+		return 2 + super.foo();
+	}
+	
+	function call(c:Parent) { }
+}

+ 1 - 0
typer.ml

@@ -2430,6 +2430,7 @@ and type_expr ctx (e,p) (with_type:with_type) =
 	| EField(_,n) when n.[0] = '$' ->
 		error "Field names starting with $ are not allowed" p
 	| EConst (Ident s) ->
+		if s = "super" && with_type <> NoValue then error "Cannot use super as value" p;
 		(try
 			acc_get ctx (type_ident_raise ~imported_enums:false ctx s p MGet) p
 		with Not_found -> try