mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
as
casting
This commit is contained in:
parent
2d597d7804
commit
cba6a6fdea
@ -6,7 +6,7 @@ import json
|
||||
import sync
|
||||
|
||||
const (
|
||||
NR_THREADS = 4
|
||||
nr_threads = 4
|
||||
)
|
||||
|
||||
struct Story {
|
||||
@ -73,7 +73,7 @@ fn main() {
|
||||
fetcher.mu = &mtx
|
||||
fetcher.wg = &wg
|
||||
fetcher.wg.add(ids.len)
|
||||
for i := 0; i < NR_THREADS; i++ {
|
||||
for i := 0; i < nr_threads; i++ {
|
||||
go fetcher.fetch()
|
||||
}
|
||||
fetcher.wg.wait()
|
||||
|
@ -44,6 +44,10 @@ fn test_float_equal_operator() {
|
||||
assert a.gtbit(1)
|
||||
assert a >= 1
|
||||
assert a.gebit(1)
|
||||
|
||||
f := 1.2
|
||||
ab := f as int
|
||||
assert ab == 1
|
||||
}
|
||||
|
||||
fn test_str_methods() {
|
||||
|
@ -60,6 +60,18 @@ fn (p mut Parser) bool_expression() string {
|
||||
p.gen('}, sizeof($typ) ), .typ = SumType_${tt} }')//${val}_type }')
|
||||
}
|
||||
}
|
||||
// `as` cast
|
||||
// TODO remove copypasta
|
||||
if p.tok == .key_as {
|
||||
p.next()
|
||||
cast_typ := p.get_type()
|
||||
if typ == cast_typ {
|
||||
p.warn('casting `$typ` to `$cast_typ` is not needed')
|
||||
}
|
||||
p.cgen.set_placeholder(start_ph, '($cast_typ)(')
|
||||
p.gen(')')
|
||||
return cast_typ
|
||||
}
|
||||
return typ
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user