Jelajahi Sumber

use TMeta instead of field hack to communicate when an abstract assignment overloads requires an assignment (closes #2405)

Simon Krajewski 11 tahun lalu
induk
melakukan
1c25e98182
3 mengubah file dengan 4 tambahan dan 3 penghapusan
  1. 1 0
      ast.ml
  2. 1 0
      common.ml
  3. 2 3
      typer.ml

+ 1 - 0
ast.ml

@@ -113,6 +113,7 @@ module Meta = struct
 		| RealPath
 		| Remove
 		| Require
+		| RequiresAssign
 		| ReplaceReflection
 		| Rtti
 		| Runtime

+ 1 - 0
common.ml

@@ -400,6 +400,7 @@ module MetaInfo = struct
 		| RealPath -> ":realPath",("Internally used on @:native types to retain original path information",[Internal])
 		| Remove -> ":remove",("Causes an interface to be removed from all implementing classes before generation",[UsedOn TClass])
 		| Require -> ":require",("Allows access to a field only if the specified compiler flag is set",[HasParam "Compiler flag to check";UsedOn TClassField])
+		| RequiresAssign -> ":requiresAssign",("Used internally to mark certain abstract operator overloads",[Internal])
 		| ReplaceReflection -> ":replaceReflection",("Used internally to specify a function that should replace its internal __hx_functionName counterpart",[Platforms [Java;Cs]; UsedOnEither[TClass;TEnum]; Internal])
 		| Rtti -> ":rtti",("Adds runtime type informations",[UsedOn TClass])
 		| Runtime -> ":runtime",("?",[])

+ 2 - 3
typer.ml

@@ -1543,7 +1543,7 @@ let rec type_binop ctx op e1 e2 is_assign_op p =
 				unify ctx eop.etype e.etype p;
 				check_assign ctx e;
 				mk (TBinop (OpAssignOp op,e,e2)) e.etype p;
-			| TField(e2,FDynamic ":needsAssign") ->
+			| TMeta((Meta.RequiresAssign,_,_),e2) ->
 				unify ctx e2.etype e.etype p;
 				check_assign ctx e;
 				mk (TBinop (OpAssign,e,e2)) e.etype p;
@@ -1825,8 +1825,7 @@ let rec type_binop ctx op e1 e2 is_assign_op p =
 		let et = type_module_type ctx (TClassDecl c) None p in
 		let ef = mk (TField (et,FStatic (c,f))) t p in
 		let ec = make_call ctx ef [e1;e2] r p in
-		(* obviously a hack to report back that we need an assignment *)
-		if is_assign_op && not assign then mk (TField(ec,FDynamic ":needsAssign")) t_dynamic p else ec
+		if is_assign_op && not assign then mk (TMeta((Meta.RequiresAssign,[],ec.epos),ec)) ec.etype ec.epos else ec
 	in
 	let cast_rec e1t e2t r is_core_type =
 		if is_core_type then