-
-
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: simplify unwrap nested selector fix (#23526)
- Loading branch information
Showing
5 changed files
with
91 additions
and
35 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
33 changes: 33 additions & 0 deletions
33
vlib/v/tests/options/option_generic_selector_unwrap_test.v
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,33 @@ | ||
type SumType = int | string | f64 | ||
|
||
struct Foo[T] { | ||
field ?SumType | ||
} | ||
|
||
fn t[T](val Foo[T]) { | ||
if val.field != none { | ||
if val.field is string { | ||
dump(val.field) | ||
assert val.field == 'foo' | ||
} else if val.field is int { | ||
dump(val.field) | ||
assert val.field == 1 | ||
} else if val.field is f64 { | ||
dump(val.field) | ||
assert val.field == 1.23 | ||
} | ||
} else { | ||
dump(val.field) | ||
assert val.field == none | ||
} | ||
} | ||
|
||
fn test_main() { | ||
t(Foo[int]{}) | ||
t(Foo[string]{}) | ||
t(Foo[f64]{}) | ||
|
||
t(Foo[int]{ field: 1 }) | ||
t(Foo[string]{ field: 'foo' }) | ||
t(Foo[f64]{ field: 1.23 }) | ||
} |
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,46 @@ | ||
module main | ||
|
||
type Foo = string | int | f32 | ||
|
||
struct Svc { | ||
mut: | ||
log ?Foo | ||
} | ||
|
||
fn t(v string) !string { | ||
return v | ||
} | ||
|
||
fn Svc.init(log ?Foo) Svc { | ||
mut svc := Svc{ | ||
log: log | ||
} | ||
if svc.log != none { | ||
if svc.log is string { | ||
assert svc.log.str() == 'foo' | ||
_ := t(svc.log) or { panic(err) } | ||
} else { | ||
assert false | ||
} | ||
assert true | ||
} | ||
return svc | ||
} | ||
|
||
struct CSvc { | ||
Svc | ||
pub mut: | ||
log ?Foo | ||
} | ||
|
||
pub fn CSvc.init(log ?Foo) CSvc { | ||
mut c := CSvc{ | ||
log: log | ||
} | ||
c.Svc = Svc.init(log) | ||
return c | ||
} | ||
|
||
fn test_main() { | ||
CSvc.init('foo') | ||
} |