Browse Source

remove closure creation for read-only class variables (fixed issue #200)

Nicolas Cannasse 14 years ago
parent
commit
0cac67f04d
1 changed files with 10 additions and 2 deletions
  1. 10 2
      typer.ml

+ 10 - 2
typer.ml

@@ -379,9 +379,17 @@ let field_access ctx mode f t e p =
 				if ctx.untyped then normal() else AKNo f.cf_name)
 		| AccNormal ->
 			(*
-				if we are reading from a read-only variable, it might actually be a method, so make sure to create a closure
+				if we are reading from a read-only variable on an anonymous object, it might actually be a method, so make sure to create a closure
 			*)
-			if mode = MGet && (match v.v_write, follow t with (AccNo | AccNever), TFun _ -> true | _ -> false) then
+			let is_maybe_method() =
+				match v.v_write, follow t, follow e.etype with
+				| (AccNo | AccNever), TFun _, TAnon a -> 
+					(match !(a.a_status) with
+					| Statics _ | EnumStatics _ -> false 
+					| _ -> true)
+				| _ -> false
+			in
+			if mode = MGet && is_maybe_method() then
 				AKExpr (mk (TClosure (e,f.cf_name)) t p)
 			else
 				normal()