-
What's happen? fn your_function(x: Int) -> StringRef:
var result: StringRef = "value"
if x == 0:
return zero()
elif x > 0 and x < 9:
result = "small"
return result
else:
result = "big"
return result
print(return)
fn zero() -> StringRef:
var result: StringRef = "zero"
return result
your_function(5) error: Expression [26]:20:11: unexpected token in expression |
Beta Was this translation helpful? Give feedback.
Answered by
DayDun
May 21, 2023
Replies: 3 comments 3 replies
-
You probably want to write |
Beta Was this translation helpful? Give feedback.
3 replies
-
Yep, agreed, I think the compiler is behaving correctly here:
|
Beta Was this translation helpful? Give feedback.
0 replies
-
Yeah, now it works, thank you fn your_function(x: Int) -> StringRef:
var result: StringRef = "value"
if x == 0:
return zero()
elif x > 0 and x < 9:
result = "small"
return result
else:
result = "big"
return result
fn zero() -> StringRef:
let result: StringRef = "zero"
return result
print(your_function(5)) or from String import String
fn your_function(x: Int) -> String:
var result: String = "value"
if x == 0:
return zero()
elif x > 0 and x < 9:
result = "small"
return result
else:
result = "big"
return result
fn zero() -> String:
let result: String = "zero"
return result
print(your_function(10)) |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Now you removed the return from the first branch. This means the function won't return anything if
x == 0
, but it must return a string to match the function signature.