Skip to content

Commit c2b0602

Browse files
committed
Add test case for elided binding if if/else node
1 parent 3ca3c2d commit c2b0602

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

tests/python/relax/test_tvmscript_parser.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1865,6 +1865,36 @@ def func(x: R.Tensor((), "int32")) -> R.Tensor((), "int32"):
18651865
return x
18661866

18671867

1868+
def test_function_with_void_return_type_in_if_else():
1869+
"""Last statement in if/else may be a void return"""
1870+
1871+
@I.ir_module
1872+
class Unsugared:
1873+
@R.function(pure=False)
1874+
def conditional(
1875+
x: R.Tensor((), "int32"), condition: R.Tensor((), "bool")
1876+
) -> R.Tensor((), "int32"):
1877+
if condition:
1878+
y = R.print(x, format="True condition: {}")
1879+
else:
1880+
y = R.print(x, format="False condition: {}")
1881+
return x
1882+
1883+
@I.ir_module
1884+
class Sugared:
1885+
@R.function(pure=False)
1886+
def conditional(
1887+
x: R.Tensor((), "int32"), condition: R.Tensor((), "bool")
1888+
) -> R.Tensor((), "int32"):
1889+
if condition:
1890+
R.print(x, format="True condition: {}")
1891+
else:
1892+
R.print(x, format="False condition: {}")
1893+
return x
1894+
1895+
tvm.ir.assert_structural_equal(Unsugared, Sugared)
1896+
1897+
18681898
def test_call_pure_packed():
18691899
@R.function
18701900
def foo(x: R.Tensor((32, 32), "float32")) -> R.Tensor:

0 commit comments

Comments
 (0)