-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Consecutive asserts ignore previous #24194
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
|
The first The 2nd This is why the combined assert works - it is resolved by the first condition, and retained for the 2nd because it's the same context. |
I think you should unwrap v until is a real string. This works: fn main() {
v := get_val()
match v {
string {
assert v == s
// assert v is string -> error: `is` can only be used with interfaces and sum types
}
else { }
}
} Once unwrapped |
Doing it explicitly is better than doing it implicitly, as @jorgeluismireles says |
Well, I am doing that, but imo both the following should work. If fn main() {
v := get_val()
assert v is string
assert v == s
} fn main() {
v := get_val()
if v !is string {
panic(error('v is not a string'))
}
if v == s {
println('do something')
}
} |
It has nothing to do with match, it is the context. The block. Whatever you wish to call it. Once something is resolved in a block, it stays resolved in a block. The only thing that isn't obvious is that Even if it appears that it should be resolved after the first assert, it isn't... it's only resolved within the assert block. This is very much the same as creating a variable inside an |
Describe the bug
An assert should be able to refine a type. But it doesn't seem to do it
Reproduction Steps
Expected Behavior
Second assert should not cause errors
Current Behavior
error: infix expr: cannot use
string
(right expression) asVal
Possible Solution
No response
Additional Information/Context
No response
V version
V 0.4.10 c2e27ef
Environment details (OS name and version, etc.)
Note
You can use the 👍 reaction to increase the issue's priority for developers.
Please note that only the 👍 reaction to the issue itself counts as a vote.
Other reactions and those to comments will not be taken into account.
The text was updated successfully, but these errors were encountered: