소스 검색

[display] don't error so hard on redefinal

closes #10412
Simon Krajewski 4 년 전
부모
커밋
5550009821
2개의 변경된 파일65개의 추가작업 그리고 1개의 파일을 삭제
  1. 1 1
      src/typing/typeloadFields.ml
  2. 64 0
      tests/display/src/cases/Issue10412.hx

+ 1 - 1
src/typing/typeloadFields.ml

@@ -798,7 +798,7 @@ module TypeBinding = struct
 				| Some (csup,_) ->
 				| Some (csup,_) ->
 					(* this can happen on -net-lib generated classes if a combination of explicit interfaces and variables with the same name happens *)
 					(* this can happen on -net-lib generated classes if a combination of explicit interfaces and variables with the same name happens *)
 					if not ((has_class_flag csup CInterface) && Meta.has Meta.CsNative c.cl_meta) then
 					if not ((has_class_flag csup CInterface) && Meta.has Meta.CsNative c.cl_meta) then
-						error ("Redefinition of variable " ^ cf.cf_name ^ " in subclass is not allowed. Previously declared at " ^ (s_type_path csup.cl_path) ) cf.cf_name_pos
+						display_error ctx ("Redefinition of variable " ^ cf.cf_name ^ " in subclass is not allowed. Previously declared at " ^ (s_type_path csup.cl_path) ) cf.cf_name_pos
 		end
 		end
 
 
 	let bind_var_expression ctx cctx fctx cf e =
 	let bind_var_expression ctx cctx fctx cf e =

+ 64 - 0
tests/display/src/cases/Issue10412.hx

@@ -0,0 +1,64 @@
+package cases;
+
+class Issue10412 extends DisplayTestCase {
+	/**
+		class Main {
+		static function main() {
+			new Game();
+		}
+		}
+
+		class Scene {
+		public var scale:Float;
+		}
+
+		class Game extends Scene {
+
+		public function new():Void {}
+
+		function itWorks():Void {
+			// There is completion:
+			// Res.|.bar;
+			Res.foo.bar;
+		}
+
+		function itDoesNot():Void {
+			// There is not:
+			// Res.|.bar;
+			Res.{-1-}.bar;
+
+			// because of `final scale`
+			// changing `final scale` to other name fixes it
+			var strangeBust = 5 / 10;
+			final scale = 5 / 10;
+			// if you comment out `strangeBust` it will also work,
+			// but not if you change `final scale` to `var scale`
+		}
+		}
+
+		class Res {
+		public static var foo = {bar: "hello"};
+		}
+	**/
+	function testOriginal() {
+		var fields = fields(pos(1));
+		eq(true, hasField(fields, "foo", "{ bar : String }"));
+	}
+
+	/**
+		class Base {
+		final x:String;
+		}
+
+		class Child extends Base {
+		final x:String;
+		function test() {
+			"".{-1-};
+		}
+		}
+	**/
+	function testActualIssue() {
+		var fields = fields(pos(1));
+		eq(true, hasField(fields, "length", "Int"));
+	}
+}