mojo
mojo copied to clipboard
[BUG] functions that raise with memory primary result type have problems
Bug Description
When I try to raise before assigning values, I get an error that seems like it incorrectly refers to self.shape
when I'd like to refer to the function parameter
error: Expression [13]:11:13: use of uninitialized value 'self.shape'
raise Error("only 2d for now")
^
Expression [13]:9:17: 'self' declared here
fn __init__(inout self, shape: DynamicVector[Int], data: DynamicVector[F64]) raises:
It works fine if I raise after the assignments though
Steps to Reproduce
struct Tensor:
var shape: DynamicVector[Int]
var data: DynamicVector[F64]
fn __init__(inout self, shape: DynamicVector[Int], data: DynamicVector[F64]) raises:
if shape.size > 2:
raise Error("only 2d for now")
self.shape = shape
self.data = data
Workaround:
struct Tensor:
var shape: DynamicVector[Int]
var data: DynamicVector[F64]
fn __init__(inout self, shape: DynamicVector[Int], data: DynamicVector[F64]) raises:
self.shape = shape
self.data = data
if shape.size > 2:
raise Error("only 2d for now")
Thanks for filing. This is a known issue with raising inside a function with a memory primary result type. @stumpOS is already working on this I think
This is fixed and will be available in the June 28 release.