Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
([GH-1380](https://github.com/NVIDIA/warp/issues/1380)).

### Fixed
- Fix Raise a `WarpCodegenTypeError` when a kernel specifies a non-`None` return type annotation but contains only a bare return.
([GH-1411](https://github.com/NVIDIA/warp/pull/1411)).

### Documentation

Expand Down
2 changes: 1 addition & 1 deletion warp/_src/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -2274,7 +2274,7 @@ def build_kernel(self, kernel):

kernel.adj.build(self)

if kernel.adj.return_var is not None:
if kernel.adj.return_var is not None or "return" in kernel.adj.arg_types:
raise WarpCodegenTypeError(f"'{kernel.key}': Error, kernels can't have return values")

def build_function(self, func):
Expand Down
18 changes: 12 additions & 6 deletions warp/tests/test_codegen.py
Original file line number Diff line number Diff line change
Expand Up @@ -554,13 +554,19 @@ def f3(x: float):
with test.assertRaisesRegex(wp.WarpCodegenTypeError, r".*Error, kernels can't have return values"):
wp.launch(f3, dim=1, inputs=[3.0], device=device)

# TODO: specifying a return type without returning a value is benign, but should be reported to avoid confusion
# @wp.kernel
# def f4(x: float) -> float:
# return
@wp.kernel(module="unique")
def f4(x: float) -> float:
return

with test.assertRaisesRegex(wp.WarpCodegenTypeError, r".*Error, kernels can't have return values"):
wp.launch(f4, dim=1, inputs=[3.0], device=device)

@wp.kernel(module="unique")
def f5(x: float) -> None:
return

# with test.assertRaisesRegex(wp.WarpCodegenTypeError, r".*Error, kernels can't have return values"):
# wp.launch(f4, dim=1, inputs=[3.0], device=device)
# -> none should remain accepted
wp.launch(f5, dim=1, inputs=[3.0], device=device)


def test_error_mutating_constant_in_dynamic_loop(test, device):
Expand Down