-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
checker: add checking for comptime assign without comptime if checking (
- Loading branch information
Showing
6 changed files
with
58 additions
and
0 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
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
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
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,7 @@ | ||
vlib/v/checker/tests/comptime_selector_assign.vv:18:24: error: mismatched types: check field type with $if to avoid this problem | ||
16 | typ.$(field.name) = 2 | ||
17 | } | ||
18 | typ.$(field.name) = 3 | ||
| ^ | ||
19 | } | ||
20 | } |
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,31 @@ | ||
import x.json2 { Any, raw_decode } | ||
|
||
struct Income { | ||
mut: | ||
email string | ||
code int | ||
} | ||
|
||
pub fn structuring[T](res Any) T { | ||
mut typ := T{} | ||
res_map := res.as_map() | ||
|
||
$for field in T.fields { | ||
if field.name in res_map { | ||
$if field.typ is int { | ||
typ.$(field.name) = 2 | ||
} | ||
typ.$(field.name) = 3 | ||
} | ||
} | ||
return typ | ||
} | ||
|
||
fn main() { | ||
res := raw_decode('{ | ||
"email": ["sdvsdv", "sds"], | ||
"code": 12 | ||
}')!.as_map() | ||
|
||
structuring[Income](res) | ||
} |
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