Browse Source

macro '#if (a != b)' should be true for missing defines (#10868)

Ben Morris 2 years ago
parent
commit
5645ecc9c3

+ 1 - 1
src/syntax/parserEntry.ml

@@ -87,7 +87,7 @@ let rec eval ctx (e,p) =
 		in
 		in
 		(match op with
 		(match op with
 		| OpEq -> compare (=)
 		| OpEq -> compare (=)
-		| OpNotEq -> compare (<>)
+		| OpNotEq -> TBool (not (is_true (compare (=))))
 		| OpGt -> compare (>)
 		| OpGt -> compare (>)
 		| OpGte -> compare (>=)
 		| OpGte -> compare (>=)
 		| OpLt -> compare (<)
 		| OpLt -> compare (<)

+ 9 - 0
tests/misc/projects/Issue10152/Main.hx

@@ -0,0 +1,9 @@
+class Main {
+	static function main () {
+	#if (foo != "bar")
+		trace("NOT EQUAL");
+	#else
+		trace("EQUAL");
+	#end
+	}
+}

+ 3 - 0
tests/misc/projects/Issue10152/compile-defined.hxml

@@ -0,0 +1,3 @@
+--main Main
+-D foo=bar
+--interp

+ 1 - 0
tests/misc/projects/Issue10152/compile-defined.hxml.stdout

@@ -0,0 +1 @@
+Main.hx:6: EQUAL

+ 2 - 0
tests/misc/projects/Issue10152/compile-undefined.hxml

@@ -0,0 +1,2 @@
+--main Main
+--interp

+ 1 - 0
tests/misc/projects/Issue10152/compile-undefined.hxml.stdout

@@ -0,0 +1 @@
+Main.hx:4: NOT EQUAL