-
-
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: fix return type checks, when returning struct values, implem…
- Loading branch information
Showing
6 changed files
with
41 additions
and
28 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
vlib/v/checker/tests/wrong_return_type_err.vv:9:10: error: cannot use `Error` as type `int` in return argument | ||
7 | fn double_positive(num int) int { | ||
8 | if num <= 0 { | ||
9 | return Error{} | ||
| ~~~~~~~ | ||
10 | } | ||
11 | return num * 2 | ||
vlib/v/checker/tests/wrong_return_type_err.vv:16:10: error: cannot use `Error` as type `Val` in return argument | ||
14 | fn new_val(num int) Val { | ||
15 | if num <= 0 { | ||
16 | return Error{} | ||
| ~~~~~~~ | ||
17 | } | ||
18 | return Val{ |
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,25 @@ | ||
module main | ||
|
||
struct Val { | ||
val int | ||
} | ||
|
||
fn double_positive(num int) int { | ||
if num <= 0 { | ||
return Error{} | ||
} | ||
return num * 2 | ||
} | ||
|
||
fn new_val(num int) Val { | ||
if num <= 0 { | ||
return Error{} | ||
} | ||
return Val{ | ||
val: num | ||
} | ||
} | ||
|
||
fn main() { | ||
println(new_val(2)) | ||
} |
File renamed without changes.
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