Ver código fonte

consider _ prefix when checking reserved keywords (#12090)

closes #12089
Simon Krajewski 4 meses atrás
pai
commit
0a60f04d4c

+ 4 - 3
src/generators/hl2c.ml

@@ -1413,16 +1413,17 @@ let generate_module_types ctx m =
 		match t with
 		| HObj o | HStruct o ->
 			let name = tname o.pname in
+			let td_name = tname ("_" ^ o.pname) in
 			ctx.defined_types <- PMap.add t () ctx.defined_types;
-			define ctx (sprintf "typedef struct _%s *%s;" name name);
+			define ctx (sprintf "typedef struct %s *%s;" td_name name);
 		| _ -> ()
 	) types;
 	line "";
 	List.iter (fun t ->
 		match t with
 		| HObj op | HStruct op ->
-			let name = tname op.pname in
-			line ("struct _" ^ name ^ " {");
+			let name = tname ("_" ^ op.pname) in
+			line ("struct " ^ name ^ " {");
 			block ctx;
 			let rec loop o =
 				(match o.psuper with

+ 9 - 0
tests/unit/src/Complex.hx

@@ -0,0 +1,9 @@
+class Complex {
+	public var i:Float;
+	public var j:Float;
+
+	public function new(inI:Float, inJ:Float) {
+		i = inI;
+		j = inJ;
+	}
+}

+ 9 - 0
tests/unit/src/unit/issues/Issue12089.hx

@@ -0,0 +1,9 @@
+package unit.issues;
+
+class Issue12089 extends Test {
+	function test() {
+		var c = new Complex(1, 2);
+		feq(1., c.i);
+		feq(2., c.j);
+	}
+}