M
Modular16mo ago
Igor

Raise returns a string?

I'm running this code:
fn test() raises -> StringRef:
raise Error("Test")


fn main() raises:
let res = test()

print(res) # prints "Test"
fn test() raises -> StringRef:
raise Error("Test")


fn main() raises:
let res = test()

print(res) # prints "Test"
It seems like if I raise an error on a function that returns a String then the error value becomes the return value... Is that expected behavior?
3 Replies
Michael K
Michael K16mo ago
You should filed a bug report (https://github.com/modularml/mojo/issues). The behavious seems specific to raising in a fn that returns a StringRef. Other return types raise appropriately and the print statement is never reached.
Igor
IgorOP16mo ago
GitHub
[BUG]: raises returns a StringRef · Issue #926 · modularml/mojo
Bug description When you have a function that returns a StringRef and it raises an error the function will return the value of that error. Is this expected behavior? Steps to reproduce fn test() ra...
Jack Clayton
Jack Clayton16mo ago
Thanks very much for the report this is currently being worked on
Want results from more Discord servers?
Add your server