瀏覽代碼

[typer] only infer getter/setter types when dealing with actual getter/setter (#10936)

* [typer] only consider as getter/setter if matching property exists

* add tests for 10935
Rudy Ges 2 年之前
父節點
當前提交
e34df73af0
共有 3 個文件被更改,包括 10 次插入1 次删除
  1. 3 1
      src/typing/typeloadFields.ml
  2. 6 0
      tests/misc/projects/Issue10935/Main.hx
  3. 1 0
      tests/misc/projects/Issue10935/build.hxml

+ 3 - 1
src/typing/typeloadFields.ml

@@ -1250,7 +1250,9 @@ let setup_args_ret ctx cctx fctx name fd p =
 	let try_find_property_type () =
 	let try_find_property_type () =
 		let name = String.sub name 4 (String.length name - 4) in
 		let name = String.sub name 4 (String.length name - 4) in
 		let cf = if fctx.is_static then PMap.find name c.cl_statics else PMap.find name c.cl_fields (* TODO: inheritance? *) in
 		let cf = if fctx.is_static then PMap.find name c.cl_statics else PMap.find name c.cl_fields (* TODO: inheritance? *) in
-		cf.cf_type
+		match Lazy.force mk, cf.cf_kind with
+			| MKGetter, Var({v_read = AccCall}) | MKSetter, Var({v_write = AccCall}) -> cf.cf_type
+			| _ -> raise Not_found;
 	in
 	in
 	let maybe_use_property_type th check def =
 	let maybe_use_property_type th check def =
 		if th = None && check() then
 		if th = None && check() then

+ 6 - 0
tests/misc/projects/Issue10935/Main.hx

@@ -0,0 +1,6 @@
+class Main {
+	public var test:Int;
+	public function set_test(i:String) {
+		test = 42;
+	}
+}

+ 1 - 0
tests/misc/projects/Issue10935/build.hxml

@@ -0,0 +1 @@
+Main