Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invert If Action #108

Merged
merged 1 commit into from
May 14, 2023
Merged

Invert If Action #108

merged 1 commit into from
May 14, 2023

Conversation

RblSb
Copy link
Member

@RblSb RblSb commented May 12, 2023

Some code duplication is started, so i moved some functions to another class. Let me know about other place/naming.
And i think this action looks pretty cool! (i hope inversion logic is good)

Demo cases:

class Main {
	static function main() {
		final obj = {flag: true};
		final arr = [0];
		var cb = (fn:()->Bool) -> false;
		while (false) {
			if (obj.flag) {
				trace("not last expr, ignore");
			}
			if (obj.flag) {
				trace(123);
			}
		}
		for (i in []) {
			trace(123);
			if (obj.flag && (obj.flag && arr[0] == 0 && cb(() -> obj.flag ? true : false)) && false) {
				trace(1);
				if (true) {
					trace(2);
				}
			}
		}
		do {
			if (obj.flag == true && !obj.flag == true) {
				trace(123);
			} else {
				trace("gen before return");
			}
		} while (false);

		if (true) {
			trace("not last expr, ignore");
		}

		if (obj.flag && (obj.flag == true) && obj.flag && arr[0] == 0) {
			trace(123);
		}
	}

	static function fooInt():Int {
		if (true) {
			trace(123);
		} else {
			trace("gen before return");
		}
		return (0 + 1);
	}

	static function fooInt2():Int {
		for (i in []) {
			if (false) {
				return 0;
			}
		}

		if (true) {
			trace(123);
			return 1;
		} else {
			trace("gen before return");
			return 0;
		}
	}

	static function fooException():Void {
		if (1 == 1) {
			trace(1);
			if (2 == 2) {
				trace(2);
			} else {
				trace("beforefoo2");
			}
		} else {
			trace("beforefoo");
		}
		throw "foo";
	}
}

@AlexHaxe
Copy link
Member

can you add some basic unittests using your demo cases? (something like ExtractConstantFeatureTest)

@AlexHaxe AlexHaxe merged commit 21e3ea3 into vshaxe:master May 14, 2023
@RblSb RblSb deleted the invert_if branch May 14, 2023 12:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants