Flip > and >= in for loop conditions to < and <= respectively #48

Closed
Desetude wants to merge 1 commits from Desetude:feature/for-loop-condition-flip into master

Here's a diff of the client produced on my branch and the one produced on master: https://gist.github.com/Desetude/1453e2df162cd508ea5f6a1da89058dc.
Resolves bullet point 6 of #7.

Here's a diff of the client produced on my branch and the one produced on master: https://gist.github.com/Desetude/1453e2df162cd508ea5f6a1da89058dc. Resolves bullet point 6 of #7.
gpe requested changes 4 years ago
class ForLoopConditionTransformer : Transformer() {
override fun transform(unit: CompilationUnit) {
unit.walk(Node.TreeTraversal.POSTORDER) { stmt: ForStmt ->
if (stmt.compare.isEmpty) {
Owner

isEmpty doesn't seem to be a function/property on Optional for me, so this doesn't build for me. I don't know if that's some sort of Kotlin set up problem on my end though.

I think I might also prefer using .ifPresent() with a lambda rather than separate isPresent() and get() calls, as it's then guaranteed that you can't forget the isPresent(). Some of the other transformers do this.

`isEmpty` doesn't seem to be a function/property on `Optional` for me, so this doesn't build for me. I don't know if that's some sort of Kotlin set up problem on my end though. I think I might also prefer using `.ifPresent()` with a lambda rather than separate `isPresent()` and `get()` calls, as it's then guaranteed that you can't forget the `isPresent()`. Some of the other transformers do this.
else -> return@walk
}
stmt.setCompare(BinaryExpr(expr.right, expr.left, flipped))
Owner

Does stmt.compare = ... work here instead? I think that'd be the preferred Kotlin style, if so.

Does `stmt.compare = ...` work here instead? I think that'd be the preferred Kotlin style, if so.
Poster

I think it doesn't work.

I think it doesn't work.
gpe approved these changes 4 years ago
Owner

cherry-picked, thanks!

cherry-picked, thanks!
gpe closed this pull request 4 years ago
Desetude deleted branch feature/for-loop-condition-flip 4 years ago
This pull request cannot be reopened because the branch was deleted.
Sign in to join this conversation.
Loading…
There is no content yet.