Skip to content

Commit

Permalink
Fix optimization interaction bug
Browse files Browse the repository at this point in the history
Fixes #4340
  • Loading branch information
SeanTAllen committed Apr 1, 2023
1 parent b62fbea commit f0af963
Showing 1 changed file with 60 additions and 0 deletions.
60 changes: 60 additions & 0 deletions test/libponyc-run/regression-4340/main.pony
@@ -0,0 +1,60 @@
use "pony_test"

interface Tree
fun get_value(): USize
fun univals(): USize
fun print_values(env: Env)

class Leaf is Tree
let _value: USize

new create(value: USize) =>
_value = value

fun print_values(env: Env) =>
None

fun get_value(): USize => _value

fun univals(): USize => 1

class Node
let _value: USize
let _left: Tree
let _right: Tree

new create(value: USize, left: Tree, right: Tree) =>
_value = value
_left = left
_right = right

fun get_value(): USize => _value

fun univals(): USize =>
let left_univals = _left.univals()
let right_univals = _right.univals()
if (_left.get_value() == _right.get_value())
and (_left.get_value() == this.get_value()) then
1 + left_univals + right_univals
else
left_univals + right_univals
end

fun print_values(env: Env) =>
env.out.print(this.univals().string())

actor Main is TestList
new create(env: Env) =>
PonyTest(env, this)

new make() =>
None

fun tag tests(test: PonyTest) =>
test(_TestUnivals)

class iso _TestUnivals is UnitTest
fun name(): String => "univals"

fun apply(h: TestHelper) =>
h.assert_eq[USize](3, Node(0, Leaf(0), Leaf(0)).univals())

0 comments on commit f0af963

Please sign in to comment.