diff --git a/CHANGELOG.md b/CHANGELOG.md index d41b5bc554..2c4c585ca2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/warp/_src/context.py b/warp/_src/context.py index a82aaff867..960cc1186f 100644 --- a/warp/_src/context.py +++ b/warp/_src/context.py @@ -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): diff --git a/warp/tests/test_codegen.py b/warp/tests/test_codegen.py index c1076f13f1..451caddf23 100644 --- a/warp/tests/test_codegen.py +++ b/warp/tests/test_codegen.py @@ -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):