-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
checker: check error for or_expr inside infix expression (#19213)
- Loading branch information
Showing
4 changed files
with
75 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
vlib/v/checker/tests/result_call_inside_infix_expr_err.out
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
vlib/v/checker/tests/result_call_inside_infix_expr_err.vv:53:27: error: wrong return type `IError` in the `or {}` block, expected `StopAfter` | ||
51 | assert parse('10d')! == StopAfter{10 * time.hour * 24, .time} | ||
52 | assert parse('10t')! == StopAfter{10, .tx} | ||
53 | assert parse('10x') or { err } == StopAfter{} | ||
| ~~~ | ||
54 | assert StopAfter{} == parse('10x') or { err } | ||
55 | } | ||
vlib/v/checker/tests/result_call_inside_infix_expr_err.vv:54:42: error: wrong return type `IError` in the `or {}` block, expected `StopAfter` | ||
52 | assert parse('10t')! == StopAfter{10, .tx} | ||
53 | assert parse('10x') or { err } == StopAfter{} | ||
54 | assert StopAfter{} == parse('10x') or { err } | ||
| ~~~ | ||
55 | } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import time | ||
|
||
enum StopAfterType { | ||
time | ||
tx | ||
} | ||
|
||
struct StopAfter { | ||
t f64 | ||
stop_after_type StopAfterType | ||
} | ||
|
||
pub fn parse(str string) !StopAfter { | ||
time_format := [str[str.len - 1]].bytestr() | ||
time_string := str[0..str.len - 1] | ||
if time_string == '0' { | ||
return StopAfter{} | ||
} | ||
timef64 := time_string.f64() | ||
if timef64 == 0 { | ||
return error('invalid string "${str}"') | ||
} | ||
|
||
match time_format { | ||
's' { | ||
return StopAfter{timef64 * time.second, .time} | ||
} | ||
'm' { | ||
return StopAfter{timef64 * time.minute, .time} | ||
} | ||
'h' { | ||
return StopAfter{timef64 * time.hour, .time} | ||
} | ||
'd' { | ||
return StopAfter{timef64 * time.hour * 24, .time} | ||
} | ||
't' { | ||
return StopAfter{timef64, .tx} | ||
} | ||
else { | ||
return error('no match for "${time_format}" format') | ||
} | ||
} | ||
} | ||
|
||
fn main() { | ||
assert parse('0s')! == StopAfter{} | ||
assert parse('10s')! == StopAfter{10 * time.second, .time} | ||
assert parse('10m')! == StopAfter{10 * time.minute, .time} | ||
assert parse('10h')! == StopAfter{10 * time.hour, .time} | ||
assert parse('10d')! == StopAfter{10 * time.hour * 24, .time} | ||
assert parse('10t')! == StopAfter{10, .tx} | ||
assert parse('10x') or { err } == StopAfter{} | ||
assert StopAfter{} == parse('10x') or { err } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters