Browse Source

[display] show fn.bind as a method in field completion (closes #6004)

Dan Korostelev 8 years ago
parent
commit
33da073b0b

+ 1 - 0
src/typing/typer.ml

@@ -3945,6 +3945,7 @@ and display_expr ctx e_ast e with_type p =
 			| TFun (args,ret) ->
 				let t = opt_args args ret in
 				let cf = mk_field "bind" (tfun [t] t) p null_pos in
+				cf.cf_kind <- Method MethNormal;
 				PMap.add "bind" cf PMap.empty
 			| _ ->
 				PMap.empty

+ 2 - 2
tests/display/src/DisplayTestCase.hx

@@ -72,8 +72,8 @@ class DisplayTestCase {
 		}
 	}
 
-	function hasField(a:Array<FieldElement>, name:String, type:String):Bool {
-		return a.exists(function(t) return t.type == type && t.name == name);
+	function hasField(a:Array<FieldElement>, name:String, type:String, ?kind:String):Bool {
+		return a.exists(function(t) return t.type == type && t.name == name && (kind == null || t.kind == kind));
 	}
 
 	function hasPath(a:Array<FieldElement>, name:String):Bool {

+ 1 - 1
tests/display/src/DisplayTestContext.hx

@@ -153,7 +153,7 @@ class DisplayTestContext {
 		}
 		var ret = [];
 		for (xml in xml.elementsNamed("i")) {
-			ret.push({name: xml.get("n"), type: xml.firstElement().firstChild().nodeValue});
+			ret.push({name: xml.get("n"), type: xml.firstElement().firstChild().nodeValue, kind: xml.get("k")});
 		}
 		return ret;
 	}

+ 3 - 2
tests/display/src/Types.hx

@@ -5,11 +5,12 @@ typedef ToplevelElement = {
 
 typedef FieldElement = {
 	name: String,
-	type: String
+	type: String,
+	kind: String,
 }
 
 abstract Position(Int) to Int {
 	public inline function new(i:Int) {
 		this = i;
 	}
-}
+}

+ 16 - 0
tests/display/src/cases/Issue6004.hx

@@ -0,0 +1,16 @@
+package cases;
+
+class Issue6004 extends DisplayTestCase {
+	/**
+	class Main {
+		static function f(a:Int) return a;
+
+		static function main() {
+			f.{-1-}
+		}
+	}
+	**/
+	function test() {
+		eq(true, hasField(fields(pos(1)), "bind", "(?a : Int -> Int) -> (?a : Int -> Int)", "method"));
+	}
+}