Browse Source

[cs] No need to cast to base class when using super. Ping #3575

Cauê Waneck 10 years ago
parent
commit
457660d546
2 changed files with 40 additions and 1 deletions
  1. 6 1
      gencommon.ml
  2. 34 0
      tests/unit/src/unit/issues/Issue3575.hx

+ 6 - 1
gencommon.ml

@@ -6202,7 +6202,12 @@ struct
 					in
 					if not (is_static || error) then match find_first_declared_field gen cl ~exact_field:{ cf with cf_type = actual_t } cf.cf_name with
 					| Some(_,actual_t,_,_,declared_cl,tl,tlch) ->
-						if declared_cl != cl && overloads_cast_to_base then begin
+						let rec is_super e = match e.eexpr with
+							| TConst TSuper -> true
+							| TParenthesis p | TMeta(_,p) -> is_super p
+							| _ -> false
+						in
+						if declared_cl != cl && overloads_cast_to_base && not (is_super !ef) then begin
 							let pos = (!ef).epos in
 							ef := {
 								eexpr = TCall(

+ 34 - 0
tests/unit/src/unit/issues/Issue3575.hx

@@ -0,0 +1,34 @@
+package unit.issues;
+
+class Issue3575 extends Test {
+	function test() {
+		eq('ChildBase!',new Child().toString());
+		eq('ChildBase!',new Child() + '');
+	}
+}
+
+
+@:nativeGen private class Base
+{
+	public function getName()
+	{
+		return "Base!";
+	}
+}
+
+class Child extends Base
+{
+	public function new()
+	{
+	}
+
+	override public function getName()
+	{
+		return "Something Else";
+	}
+
+	public function toString()
+	{
+		return 'Child' + super.getName();
+	}
+}