瀏覽代碼

allow parsing postfix ! but fail during typing (closes #4284)

Simon Krajewski 9 年之前
父節點
當前提交
2a5c5cb220
共有 3 個文件被更改,包括 22 次插入2 次删除
  1. 2 2
      ast.ml
  2. 19 0
      tests/unit/src/unit/issues/Issue4284.hx
  3. 1 0
      typer.ml

+ 2 - 2
ast.ml

@@ -465,8 +465,8 @@ let is_lower_ident i =
 let pos = snd
 let pos = snd
 
 
 let rec is_postfix (e,_) op = match op with
 let rec is_postfix (e,_) op = match op with
-	| Increment | Decrement -> true
-	| Not | Neg | NegBits -> false
+	| Increment | Decrement | Not -> true
+	| Neg | NegBits -> false
 
 
 let is_prefix = function
 let is_prefix = function
 	| Increment | Decrement -> true
 	| Increment | Decrement -> true

+ 19 - 0
tests/unit/src/unit/issues/Issue4284.hx

@@ -0,0 +1,19 @@
+package unit.issues;
+
+private abstract A(String) {
+	public inline function new(s) this = s;
+
+	@:op(A!) function opNot() {
+		return this.toUpperCase();
+	}
+}
+
+class Issue4284 extends Test {
+	function test() {
+		var a = new A("foo");
+		eq("FOO", a!);
+
+		var b = true;
+		t(unit.TestType.typeError(b!));
+	}
+}

+ 1 - 0
typer.ml

@@ -2342,6 +2342,7 @@ and type_unop ctx op flag e p =
 		let make e =
 		let make e =
 			let t = (match op with
 			let t = (match op with
 			| Not ->
 			| Not ->
+				if flag = Postfix then error "Postfix ! is not supported" p;
 				unify ctx e.etype ctx.t.tbool e.epos;
 				unify ctx e.etype ctx.t.tbool e.epos;
 				ctx.t.tbool
 				ctx.t.tbool
 			| Increment
 			| Increment