V version:
V 0.1.26 50a8373.9aa1a65
OS:
linux amd64
What did you do?
fn a() string {
"""same with this code
match 1 {
1 {
}
else {
return ""
}
}
"""
if false {
return "a"
}
}
fn main() {
a_null := a()
println(a_null)
}
What did you expect to see?
compiler error: "error: missing return at end of function a"
What did you see instead?
(null)
yeah it results in an error in simple cases like
fn a() string {}
Maybe for now, when no full analysis is implemented, it could be implemented as: require a return statement of valid return type at same scope as the function body. Additional conditions like if and match are allowed.
The following valid code woulde be illegal after this change (until no full analysis is implemented):
fn a() string {
if 1 == 1 {
return "1"
} else {
return "2"
}
}
The full analysis was implemented in V1, so it should be trivial to bring it back.
Doing this will break lots of existing code.
Ok, then for now you could just set a default value of T as return value for this case, I think that wouldnt break code. This would also prevent null cases, if the full analysis had unchecked cases / bugs.
Now is a good time to break code this way. Lots of other things have been broken along the way from V1 to V2, so better to break this now than carry that technical debt into the future.