Browse Source

add EnumValue.match dummy for documentation and remove special completion handling from compiler

Simon Krajewski 11 years ago
parent
commit
dcbbace980
2 changed files with 36 additions and 10 deletions
  1. 36 4
      std/haxe/EnumTools.hx
  2. 0 6
      typer.ml

+ 36 - 4
std/haxe/EnumTools.hx

@@ -62,10 +62,10 @@ extern class EnumTools {
 		The constructor indices are preserved from haxe syntax, so the first
 		declared is index 0, the next index 1 etc.
 
-		If `e` or `constr` is null, or if enum `e` has no constructor named
-		`constr`, or if the number of elements in `params` does not match the
-		expected number of constructor arguments, or if any argument has an
-		invalid type, the result is unspecified.
+		If `e` or `index` is null, or if enum `e` has no constructor
+		corresponding to index `index`, or if the number of elements in `params`
+		does not match the expected number of constructor arguments, or if any
+		argument has an invalid type, the result is unspecified.
 	**/
 	static public inline function createByIndex<T>(e:Enum<T>, index:Int, ?params:Array<Dynamic>):T {
 		return Type.createEnumIndex(e, index, params);
@@ -151,4 +151,36 @@ extern class EnumValueTools {
 	static public inline function getIndex(e:EnumValue):Int {
 		return Type.enumIndex(e);
 	}
+
+	/**
+		Matches enum instance `e` against pattern `pattern`, returning true if
+		matching succeeded and false otherwise.
+
+		Example usage:
+
+		```
+		if (e.match(pattern)) {
+			// codeIfTrue
+		} else {
+			// codeIfFalse
+		}
+		```
+
+		This is equivalent to the following code:
+
+		```
+		switch (e) {
+			case pattern:
+				// codeIfTrue
+			case _:
+				// codeIfFalse
+		}
+		```
+
+		This method is implemented in the compiler. This definition exists only
+		for documentation.
+	**/
+	static public function match(e:EnumValue, pattern:Dynamic):Bool {
+		return false;
+	}
 }

+ 0 - 6
typer.ml

@@ -3474,9 +3474,6 @@ and handle_display ctx e iscall p =
 				if field_name fa = "bind" then (match follow e1.etype with
 					| TFun(args,ret) -> {e1 with etype = opt_args args ret}
 					| _ -> e)
-				else if field_name fa = "match" then (match follow e1.etype with
-					| TEnum _ as t -> {e1 with etype = tfun [t] ctx.t.tbool }
-					| _ -> e)
 				else
 					e
 			| _ ->
@@ -3571,9 +3568,6 @@ and handle_display ctx e iscall p =
 				let t = opt_args args ret in
 				let cf = mk_field "bind" (tfun [t] t) p in
 				PMap.add "bind" cf PMap.empty
-			| TEnum(_) as t ->
-				let cf = mk_field "match" (tfun [t] ctx.t.tbool) p in
-				PMap.add "match" cf PMap.empty
 			| _ ->
 				PMap.empty
 		in