Skip to content

Commit 3639455

Browse files
committed
Fix constant folding JS bug
1 parent 6163969 commit 3639455

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

library/src/commonTest/kotlin/effekt/casestudies/AutomaticDifferentiation.kt

+6-5
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,15 @@ class AutomaticDifferentiationTest {
2525

2626
forwards(0.0) { progExp(it) } shouldBe mathExp(1.0)
2727
backwards(0.0) { progExp(it) } shouldBe mathExp(1.0)
28+
val one = 1.0
2829

2930
showString { x ->
3031
forwardsHigher(x) { x ->
3132
forwardsHigher(x) { y ->
3233
forwardsHigher(y) { z -> prog(z) }
3334
}
3435
}
35-
} shouldBe "(((${1.0} + ${1.0}) + ((${1.0} + ${1.0}) * ${1.0})) + ((${1.0} + ${1.0}) * ${1.0}))"
36+
} shouldBe "((($one + $one) + (($one + $one) * $one)) + (($one + $one) * $one))"
3637

3738

3839
// we have the same pertubation confusion as in Lantern
@@ -90,14 +91,14 @@ suspend fun <N> AD<N>.forwardsHigher(x: N, prog: suspend AD<NumH<N>>.(NumH<N>) -
9091
suspend fun showString(prog: suspend AD<String>.(String) -> String) = object : AD<String> {
9192
override val Double.num: String get() = toString()
9293
override suspend fun String.plus(other: String) = when {
93-
this == "${0.0}" -> other
94-
other == "${0.0}" -> this
94+
this == 0.0.toString() -> other
95+
other == 0.0.toString() -> this
9596
else -> "($this + $other)"
9697
}
9798

9899
override suspend fun String.times(other: String) = when {
99-
this == "${0.0}" || other == "${0.0}" -> "${0.0}"
100-
this == "${1.0}" -> other
100+
this == 0.0.toString() || other == 0.0.toString() -> 0.0.toString()
101+
this == 1.0.toString() -> other
101102
else -> "($this * $other)"
102103
}
103104

0 commit comments

Comments
 (0)