interpolated string not evaluating in assert? #25658
-
|
consider this code: assert false, "Parsing failed: ${err}"my question, is it expected and acceptable that when this fires, it prints: I feel like that is completely unintuitive, I'm not certain as to why a runtime assertion wouldn't evaluate its both of it's operands, unless Also, sorry if they're not called "interpolated strings", I've just started learning the language, and that's what I know them as. I'm considering creating an issue about this, but I'm not certain that this warrants it. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
|
Your line will work if there exist fn divide(a int, b int) ! int {
if b == 0 {
return error('denominator can\'t be zero')
}
return a/b
}
fn main() {
q := divide(10, 0) or {
assert false, 'divide error: ${err}'
0
}
dump(q)
}https://play.vlang.io/p/cb4fa0ac1d The |
Beta Was this translation helpful? Give feedback.
Your line will work if there exist
errvariable like in next program.https://play.vlang.io/p/cb4fa0ac1d
The
dividefunction returns a Result, that is, a possibility of a value or an error (when denominator is zero). By calling the divide function the compiler requires anor { ... }block where to go when the error is triggered, inside the block…